[gdb/build] Fix build with undefined CXX_STD_THREAD

Message ID 20210907145006.GA4878@delia
State New
Headers show
Series
  • [gdb/build] Fix build with undefined CXX_STD_THREAD
Related show

Commit Message

Tom de Vries via Gdb-patches Sept. 7, 2021, 2:50 p.m.
Hi,

When building gdb on openSUSE Leap 42.3, we trigger the case that
CXX_STD_THREAD is undefined, and run into:
...
gdb/maint.c: In function ‘void maintenance_show_worker_threads \
  (ui_file*, int, cmd_list_element*, const char*)’:
gdb/maint.c:877:14: error: ‘gdb::thread_pool’ has not been declared
         gdb::thread_pool::g_thread_pool->thread_count ());
              ^
Makefile:1647: recipe for target 'maint.o' failed
make[1]: *** [maint.o] Error 1
...

Fix this by handling the undefined CXX_STD_THREAD case in
maintenance_show_worker_threads, such that we get:
...
$ gdb -q -batch -ex "maint show worker-thread"
The number of worker threads GDB can use is 0.
...

Tested on x86_64-linux.

Any comments?

Thanks,
- Tom

[gdb/build] Fix build with undefined CXX_STD_THREAD

---
 gdb/maint.c | 5 +++++
 1 file changed, 5 insertions(+)

Comments

Tom de Vries via Gdb-patches Sept. 7, 2021, 3:19 p.m. | #1
On 9/7/21 4:50 PM, Tom de Vries via Gdb-patches wrote:
> Hi,

> 

> When building gdb on openSUSE Leap 42.3, we trigger the case that

> CXX_STD_THREAD is undefined, and run into:

> ...

> gdb/maint.c: In function ‘void maintenance_show_worker_threads \

>   (ui_file*, int, cmd_list_element*, const char*)’:

> gdb/maint.c:877:14: error: ‘gdb::thread_pool’ has not been declared

>          gdb::thread_pool::g_thread_pool->thread_count ());

>               ^

> Makefile:1647: recipe for target 'maint.o' failed

> make[1]: *** [maint.o] Error 1

> ...

> 

> Fix this by handling the undefined CXX_STD_THREAD case in

> maintenance_show_worker_threads, such that we get:

> ...

> $ gdb -q -batch -ex "maint show worker-thread"

> The number of worker threads GDB can use is 0.

> ...

> 

> Tested on x86_64-linux.

> 

> Any comments?

> 


Btw, I just found a related issue.

I find:
...
CXX_DIALECT='-std=gnu++11'
...
in the config.log, but that setting is not used when checking for
CXX_STD_THREAD, so we have:
...
configure:14614: checking for std::thread
configure:14631: g++ -c -pthread -Wall -O2 -g     conftest.cpp >&5
In file included from /usr/include/c++/4.8/thread:35:0,
                 from conftest.cpp:167:
/usr/include/c++/4.8/bits/c++0x_warning.h:32:2: error: #error This file
requires compiler and library support for the ISO C++ 2011 standard.
This support is currently experimental, and must be enabled with the
-std=c++11 or -std=gnu++11 compiler options.
 #error This file requires compiler and library support for the \
  ^
conftest.cpp: In function 'int main()':
conftest.cpp:172:1: error: 'thread' is not a member of 'std'
 std::thread t(callback);
 ^
conftest.cpp:172:13: error: expected ';' before 't'
 std::thread t(callback);
             ^
configure:14631: $? = 1
...

It could be that:
...
$ g++ -std=gnu++11 -c -pthread -Wall -O2 -g     conftest.cpp
...
actually would succeed.

Thanks,
- Tom
Tom de Vries via Gdb-patches Sept. 7, 2021, 4:12 p.m. | #2
BTW, it seems https://sourceware.org/bugzilla/show_bug.cgi?id=28312
was filed for this.

Christian

On Tue, Sep 7, 2021 at 11:22 AM Tom de Vries via Gdb-patches
<gdb-patches@sourceware.org> wrote:
>

> On 9/7/21 4:50 PM, Tom de Vries via Gdb-patches wrote:

> > Hi,

> >

> > When building gdb on openSUSE Leap 42.3, we trigger the case that

> > CXX_STD_THREAD is undefined, and run into:

> > ...

> > gdb/maint.c: In function ‘void maintenance_show_worker_threads \

> >   (ui_file*, int, cmd_list_element*, const char*)’:

> > gdb/maint.c:877:14: error: ‘gdb::thread_pool’ has not been declared

> >          gdb::thread_pool::g_thread_pool->thread_count ());

> >               ^

> > Makefile:1647: recipe for target 'maint.o' failed

> > make[1]: *** [maint.o] Error 1

> > ...

> >

> > Fix this by handling the undefined CXX_STD_THREAD case in

> > maintenance_show_worker_threads, such that we get:

> > ...

> > $ gdb -q -batch -ex "maint show worker-thread"

> > The number of worker threads GDB can use is 0.

> > ...

> >

> > Tested on x86_64-linux.

> >

> > Any comments?

> >

>

> Btw, I just found a related issue.

>

> I find:

> ...

> CXX_DIALECT='-std=gnu++11'

> ...

> in the config.log, but that setting is not used when checking for

> CXX_STD_THREAD, so we have:

> ...

> configure:14614: checking for std::thread

> configure:14631: g++ -c -pthread -Wall -O2 -g     conftest.cpp >&5

> In file included from /usr/include/c++/4.8/thread:35:0,

>                  from conftest.cpp:167:

> /usr/include/c++/4.8/bits/c++0x_warning.h:32:2: error: #error This file

> requires compiler and library support for the ISO C++ 2011 standard.

> This support is currently experimental, and must be enabled with the

> -std=c++11 or -std=gnu++11 compiler options.

>  #error This file requires compiler and library support for the \

>   ^

> conftest.cpp: In function 'int main()':

> conftest.cpp:172:1: error: 'thread' is not a member of 'std'

>  std::thread t(callback);

>  ^

> conftest.cpp:172:13: error: expected ';' before 't'

>  std::thread t(callback);

>              ^

> configure:14631: $? = 1

> ...

>

> It could be that:

> ...

> $ g++ -std=gnu++11 -c -pthread -Wall -O2 -g     conftest.cpp

> ...

> actually would succeed.

>

> Thanks,

> - Tom

>
Tom de Vries via Gdb-patches Sept. 8, 2021, 7:02 a.m. | #3
On 9/7/21 6:12 PM, Christian Biesinger wrote:
> BTW, it seems https://sourceware.org/bugzilla/show_bug.cgi?id=28312

> was filed for this.

> 


Thanks, I've added a Bug tag.

Pushed as attached.  I've rewritten it a bit to avoid introducing a 3rd
printf.

Thanks,
- Tom
[gdb/build] Fix build with undefined CXX_STD_THREAD

When building gdb on openSUSE Leap 42.3, we trigger the case that
CXX_STD_THREAD is undefined, and run into:
...
gdb/maint.c: In function 'void maintenance_show_worker_threads \
  (ui_file*, int, cmd_list_element*, const char*)':
gdb/maint.c:877:14: error: 'gdb::thread_pool' has not been declared
         gdb::thread_pool::g_thread_pool->thread_count ());
              ^
Makefile:1647: recipe for target 'maint.o' failed
make[1]: *** [maint.o] Error 1
...

Fix this by handling the undefined CXX_STD_THREAD case in
maintenance_show_worker_threads, such that we get:
...
$ gdb -q -batch -ex "maint show worker-thread"
The number of worker threads GDB can use is 0.
...

Tested on x86_64-linux.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=28312

---
 gdb/maint.c | 23 ++++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)

diff --git a/gdb/maint.c b/gdb/maint.c
index cbd7d4ed47b..8f8bdc87be8 100644
--- a/gdb/maint.c
+++ b/gdb/maint.c
@@ -871,14 +871,23 @@ maintenance_show_worker_threads (struct ui_file *file, int from_tty,
 				 struct cmd_list_element *c,
 				 const char *value)
 {
+#if CXX_STD_THREAD
   if (n_worker_threads == -1)
-    fprintf_filtered (file, _("The number of worker threads GDB "
-			      "can use is unlimited (currently %zu).\n"),
-		      gdb::thread_pool::g_thread_pool->thread_count ());
-  else
-    fprintf_filtered (file, _("The number of worker threads GDB "
-			      "can use is %d.\n"),
-		      n_worker_threads);
+    {
+      fprintf_filtered (file, _("The number of worker threads GDB "
+				"can use is unlimited (currently %zu).\n"),
+			gdb::thread_pool::g_thread_pool->thread_count ());
+      return;
+    }
+#endif
+
+  int report_threads = 0;
+#if CXX_STD_THREAD
+  report_threads = n_worker_threads;
+#endif
+  fprintf_filtered (file, _("The number of worker threads GDB "
+			    "can use is %d.\n"),
+		    report_threads);
 }
Tom de Vries via Gdb-patches Sept. 8, 2021, 8:06 a.m. | #4
On 9/7/21 5:19 PM, Tom de Vries wrote:
> I find:

> ...

> CXX_DIALECT='-std=gnu++11'

> ...

> in the config.log, but that setting is not used when checking for

> CXX_STD_THREAD, so we have:

> ...

> configure:14614: checking for std::thread

> configure:14631: g++ -c -pthread -Wall -O2 -g     conftest.cpp >&5

> In file included from /usr/include/c++/4.8/thread:35:0,

>                  from conftest.cpp:167:

> /usr/include/c++/4.8/bits/c++0x_warning.h:32:2: error: #error This file

> requires compiler and library support for the ISO C++ 2011 standard.

> This support is currently experimental, and must be enabled with the

> -std=c++11 or -std=gnu++11 compiler options.

>  #error This file requires compiler and library support for the \

>   ^

> conftest.cpp: In function 'int main()':

> conftest.cpp:172:1: error: 'thread' is not a member of 'std'

>  std::thread t(callback);

>  ^

> conftest.cpp:172:13: error: expected ';' before 't'

>  std::thread t(callback);

>              ^

> configure:14631: $? = 1

> ...

> 

> It could be that:

> ...

> $ g++ -std=gnu++11 -c -pthread -Wall -O2 -g     conftest.cpp

> ...

> actually would succeed.


Filed PR28318 - "[gdb/build] std::thread support configure check does
not use CXX_DIALECT"  here (
https://sourceware.org/bugzilla/show_bug.cgi?id=28318 ).

Thanks,
- Tom

Patch

diff --git a/gdb/maint.c b/gdb/maint.c
index cbd7d4ed47b..56a197c2a14 100644
--- a/gdb/maint.c
+++ b/gdb/maint.c
@@ -871,6 +871,7 @@  maintenance_show_worker_threads (struct ui_file *file, int from_tty,
 				 struct cmd_list_element *c,
 				 const char *value)
 {
+#if CXX_STD_THREAD
   if (n_worker_threads == -1)
     fprintf_filtered (file, _("The number of worker threads GDB "
 			      "can use is unlimited (currently %zu).\n"),
@@ -879,6 +880,10 @@  maintenance_show_worker_threads (struct ui_file *file, int from_tty,
     fprintf_filtered (file, _("The number of worker threads GDB "
 			      "can use is %d.\n"),
 		      n_worker_threads);
+#else
+  fprintf_filtered (file, _("The number of worker threads GDB "
+			    "can use is 0.\n"));
+#endif
 }