public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] 0001-Fix-multi-thread-debug-bug-in-AIX.patch
@ 2022-10-25  6:47 Aditya Kamath1
  2022-10-28  9:49 ` Ulrich Weigand
  0 siblings, 1 reply; 49+ messages in thread
From: Aditya Kamath1 @ 2022-10-25  6:47 UTC (permalink / raw)
  To: Ulrich Weigand, simark, Aditya Kamath1 via Gdb-patches; +Cc: Sangamesh Mallayya


[-- Attachment #1.1: Type: text/plain, Size: 2574 bytes --]

Hi all,

In the latest gdb AIX users aren't able to debug multi threaded programs.

I have fixed it. Please find attached the patch. [See 0001-Fix-multi-thread-debug-bug-in-AIX.patch].

Also pasting the output of the failure and the output after adding the patch.

Kindly let me know if any change required, if not kindly push this patch so that AIX folks have a happy multi threaded debugging.

Have a nice day ahead.

Thanks and regards,
Aditya.

---------------------------------------------------------

The code:- [Program Credits:- GDB TESTSUITE gdb_threads/continue-pending-status.c ]


#include <unistd.h>

#include <stdlib.h>

#include <pthread.h>

#include <assert.h>


pthread_barrier_t barrier;


#define NUM_THREADS 2


void *

thread_function (void *arg)

{

  pthread_barrier_wait (&barrier);

  while (1);

}


int

main (void)

{

  int i;


  alarm (300);


  pthread_barrier_init (&barrier, NULL, NUM_THREADS);


  for (i = 0; i < NUM_THREADS; i++)

    {

      pthread_t thread;

      int res;


      res = pthread_create (&thread, NULL,

                            thread_function, NULL);

      assert (res == 0);

    }


  while (1)

    sleep (1);


  return 0;

}

OUTPUT BEFORE PATCH:-


(gdb) r

Starting program: /home/gdb_tests/continue-pending-status

[New Thread 1]

./../gdbsupport/gdb-checked-static-cast.h:58: internal-error: checked_static_cast: Assertion `result != nullptr' failed.

A problem internal to GDB has been detected,

further debugging may prove unreliable.

----- Backtrace -----

0x1010fb657 ???

0x1010fb81f ???


OUTPUT AFTER PATCH


(gdb) r

Starting program: /home/gdb_tests/continue-pending-status

[New Thread 1]

^C[New Thread 258]

[New Thread 515]


Thread 1 received signal SIGINT, Interrupt.

0xd0595fb0 in _p_nsleep () from /usr/lib/libpthread.a(shr_xpg5.o)

(gdb) info threads

  Id   Target Id                          Frame

* 1    process 7602548                    0xd0595fb0 in _p_nsleep ()

   from /usr/lib/libpthread.a(shr_xpg5.o)

  2    Thread 1 (tid 27984319, running)   0xd0595fb0 in _p_nsleep ()

   from /usr/lib/libpthread.a(shr_xpg5.o)

  3    Thread 258 (tid 37093859, running) thread_function (arg=0x0)

    at continue-pending-status.c:36

  4    Thread 515 (tid 35062111, running) thread_function (arg=warning: (Internal error: pc 0x0 in read in psymtab, but not in symtab.)


0x0)

    at continue-pending-status.c:36

(gdb) q



[-- Attachment #2: 0001-Fix-multi-thread-debug-bug-in-AIX.patch --]
[-- Type: application/octet-stream, Size: 1369 bytes --]

From 15797e8153fd90e6f457cc3bcd0237fbfd4491d4 Mon Sep 17 00:00:00 2001
From: Aditya Vidyadhar Kamath <Aditya.Kamath1@ibm.com>
Date: Tue, 25 Oct 2022 01:35:33 -0500
Subject: [PATCH] Fix multi thread debug bug in AIX

In the recent commit 98ed24fb35d89eb20179edf6c12f599c7a9e228e made by Mr. Tom there is a change in aix-thread.c file that changes

 static_cast <aix_thread_info *> in gdb to gdb::checked_static_cast <aix_thread_info *>

AIX folks using the latest version will not be able to debug multi thread programs as a result of it.

The error in AIX is as follows:-

internal-error: checked_static_cast: Assertion 'result != nullptr' failed.

The reason is that the first thread in a multi threaded program will not have a prev.

Hence we need to add this check.

The future threads if any will handle the change gdb::checked_static_cast with ease after this condition is checked.
---
 gdb/aix-thread.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/gdb/aix-thread.c b/gdb/aix-thread.c
index e556c153576..b2dabd242fc 100644
--- a/gdb/aix-thread.c
+++ b/gdb/aix-thread.c
@@ -90,6 +90,9 @@ struct aix_thread_info : public private_thread_info
 static aix_thread_info *
 get_aix_thread_info (thread_info *thread)
 {
+  if (thread->priv == NULL)
+    return NULL;
+
   return gdb::checked_static_cast<aix_thread_info *> (thread->priv.get ());
 }
 
-- 
2.31.1


^ permalink raw reply	[flat|nested] 49+ messages in thread
* Re: [PATCH] 0001-Fix-multi-thread-debug-bug-in-AIX.patch
@ 2022-11-08 12:00 Aditya Kamath1
  0 siblings, 0 replies; 49+ messages in thread
From: Aditya Kamath1 @ 2022-11-08 12:00 UTC (permalink / raw)
  To: Ulrich Weigand, simark, gdb-patches; +Cc: Sangamesh Mallayya

[-- Attachment #1: Type: text/plain, Size: 3999 bytes --]

Hi Ulrich,


>You should find out why the "priv" field isn't
>set up correctly, and fix whatever was going
>wrong there.  (I believe this should have been
>done in sync_threadlists.)

You were right about this. What is happening is the main process and the thread representing it are treated as two separate threads by the libpthread library. Main process had no private data set whereas the thread representing it had. Usually, both of them should have it and their private data must be the same.

For example ,

Consider the program below:- [ Program Credits:-  GDB test case continue-pending-status.c]


#include <stdio.h>

#include <unistd.h>

#include <stdlib.h>

#include <pthread.h>

#include <assert.h>


pthread_barrier_t barrier;


#define NUM_THREADS 2


void *

thread_function (void *arg)

{



  pthread_barrier_wait (&barrier);


  while (1); /* break here */

}


int

main (void)

{

  int i;


  alarm (300);


  pthread_barrier_init (&barrier, NULL, NUM_THREADS);


  for (i = 0; i < NUM_THREADS; i++)

    {

      pthread_t thread;

      int res;


      res = pthread_create (&thread, NULL,

                            thread_function, NULL);

      assert (res == 0);

    }

  while (1)

    sleep (1);


  return 0;

}

Here is the gdb output of the above code,  Clearly when I switched to thread 2 which same as thread1 and interrupted, thread 1 received the input. So, when we added a private data in sync_threadlists() we added for thread 2 but not 1 which is main thread and same as thread 1. This is why we got that assertion failure as thread 1 did not have a private data.


Reading symbols from /home/XYZ/gdb_tests/continue-pending-status...

(gdb) r

Starting program: /home/XYZ/gdb_tests/continue-pending-status

[New Thread 1]

^C[New Thread 258]

[New Thread 515]


Thread 1 received signal SIGINT, Interrupt.

0xd0595fb0 in _p_nsleep () from /usr/lib/libpthread.a(shr_xpg5.o)

(gdb) info threads

  Id   Target Id                          Frame

* 1    process 12059046                   0xd0595fb0 in _p_nsleep () from /usr/lib/libpthread.a(shr_xpg5.o)

  2    Thread 1 (tid 39125487, running)   0xd0595fb0 in _p_nsleep () from /usr/lib/libpthread.a(shr_xpg5.o)

  3    Thread 258 (tid 23396809, running) thread_function (arg=0x0) at continue-pending-status.c:36

  4    Thread 515 (tid 36503883, running) thread_function (arg=warning: (Internal error: pc 0x0 in read in psymtab, but not in symtab.)


0x0) at continue-pending-status.c:36

(gdb) thread 2

[Switching to thread 2 (Thread 1)]

#0  0xd0595fb0 in _p_nsleep () from /usr/lib/libpthread.a(shr_xpg5.o)

(gdb) c

Continuing.

^C

Thread 1 received signal SIGINT, Interrupt.

[Switching to process 12059046]

0xd0595fb0 in _p_nsleep () from /usr/lib/libpthread.a(shr_xpg5.o)

(gdb)

I have written my comments in the patch. Hope this works and if it is right kindly push the same in git, otherwise Let me know what you think.

Have a nice day ahead.

Thanks and regards,
Aditya.
________________________________
From: Ulrich Weigand <Ulrich.Weigand@de.ibm.com>
Sent: 28 October 2022 15:19
To: simark@simark.ca <simark@simark.ca>; Aditya Kamath1 <Aditya.Kamath1@ibm.com>; gdb-patches@sourceware.org <gdb-patches@sourceware.org>
Cc: Sangamesh Mallayya <sangamesh.swamy@in.ibm.com>
Subject: Re: [PATCH] 0001-Fix-multi-thread-debug-bug-in-AIX.patch

Aditya Kamath1 <Aditya.Kamath1@ibm.com> wrote:

> static aix_thread_info *
> get_aix_thread_info (thread_info *thread)
> {
>+  if (thread->priv == NULL)
>+    return NULL;

This doesn't look right.  Note that all users of
get_aix_thread_info assume the pointer returned
from there is never NULL.

You should find out why the "priv" field isn't
set up correctly, and fix whatever was going
wrong there.  (I believe this should have been
done in sync_threadlists.)

Bye,
Ulrich


^ permalink raw reply	[flat|nested] 49+ messages in thread

end of thread, other threads:[~2023-02-17 19:14 UTC | newest]

Thread overview: 49+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-25  6:47 [PATCH] 0001-Fix-multi-thread-debug-bug-in-AIX.patch Aditya Kamath1
2022-10-28  9:49 ` Ulrich Weigand
2022-11-08 12:00   ` Aditya Kamath1
2022-11-08 12:17     ` Ulrich Weigand
2022-11-13 18:15       ` Aditya Kamath1
2022-11-15 18:16         ` Ulrich Weigand
2022-11-21  8:27           ` Aditya Kamath1
2022-11-23 14:15             ` Ulrich Weigand
2022-11-23 16:03               ` Aditya Kamath1
2022-11-23 17:09                 ` Ulrich Weigand
2022-11-23 18:45                   ` Aditya Kamath1
2022-11-29  8:18                     ` Aditya Kamath1
2022-11-30 14:57                       ` Ulrich Weigand
2022-12-02  7:50                         ` Aditya Kamath1
2022-12-05 18:33                           ` Ulrich Weigand
2022-12-08 10:28                             ` Aditya Kamath1
2022-12-08 10:46                               ` Aditya Kamath1
2022-12-08 16:29                               ` Ulrich Weigand
2022-12-15 12:58                                 ` Aditya Kamath1
2022-12-15 15:53                                   ` Ulrich Weigand
2022-12-19  6:30                                     ` Aditya Kamath1
2022-12-22 12:50                                       ` Ulrich Weigand
2022-12-26 13:18                                         ` Aditya Kamath1
2023-01-09 14:04                                           ` Ulrich Weigand
2023-01-10 12:23                                             ` Aditya Kamath1
2023-01-11 13:31                                               ` Ulrich Weigand
2023-01-13 14:06                                                 ` Aditya Kamath1
2023-01-20 14:44                                                   ` Ulrich Weigand
2023-01-27 14:40                                                     ` Aditya Kamath1
2023-01-30 19:54                                                       ` Tom Tromey
2023-02-02  6:24                                                       ` Aditya Kamath1
2023-02-02  6:35                                                         ` Aditya Kamath1
2023-02-02 17:43                                                           ` Ulrich Weigand
2023-02-03 11:10                                                             ` Aditya Kamath1
2023-02-06 19:07                                                               ` Ulrich Weigand
2023-02-07 11:57                                                                 ` Aditya Kamath1
2023-02-08 18:44                                                                   ` Ulrich Weigand
2023-02-10 16:33                                                                     ` Aditya Kamath1
2023-02-10 16:46                                                                       ` Aditya Kamath1
2023-02-13 19:01                                                                       ` Ulrich Weigand
2023-02-14 14:13                                                                         ` Aditya Kamath1
2023-02-16 19:46                                                                           ` Ulrich Weigand
2023-02-17 11:26                                                                             ` Aditya Kamath1
2023-02-17 12:04                                                                               ` Ulrich Weigand
2023-02-17 13:22                                                                                 ` Aditya Kamath1
2023-02-17 14:18                                                                                   ` Ulrich Weigand
2023-02-17 15:15                                                                                     ` Aditya Kamath1
2023-02-17 19:14                                                                                       ` Ulrich Weigand
2022-11-08 12:00 Aditya Kamath1

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).