Hello,

Michael Kelly, le sam. 09 mai 2026 19:32:12 +0100, a ecrit:
> On 08/05/2026 00:29, Samuel Thibault wrote:
> > I haven't looked at the details of thread_db, but the way I understand
> > it is that thread_db can use the gdbserver protocol to ask qemu to
> > access various parts of the memory, to get the information it needs.
> > I.e. qemu wouldn't need any change, it is just a proxy to the gnumach
> > memory. Gnumach itself doesn't need to do anything, it's qemu that
> > accesses the memory. And it's thread_db which knows which variables
> > should be read to get the threads list and their register statuses, etc.
> 
> I confess that I hadn't thought of the prospect of a custom thread_db making
> calls out to the remote debugger stub.

I don't think thread_db has to make anything particular.

Again, I have never really dived into the details, but my understanding
is that thread_db tells gdb the memory layout of the thread structures
etc. and it's gdb itself which uses the gdbserver protocol to access the
memory of the debugged process and interpret is as thread_db told it to.

See:

https://docs.oracle.com/cd/E19455-01/816-3324/6m9k4vdpl/index.html

the controlling process is linked with libthread_db, and it calls routines in 
libthread_db. libthread_db in turn calls certain routines that it expects the 
controlling process to provide. These process control primitives allow 
libthread_db to:

    Look up symbols in a target process.

    Stop and continue individual lightweight processes ( LWPs) within a target 
process.

    Stop and continue an entire target process.

    Read and write memory and registers in a target process.

> My point being that it seems like it is expected that thread_db lives
> outside of gdb and is called by gdb. It does not make use of any gdb
> function but rather it provides necessary data to gdb.

According to the thread_db documentation, it can use some gdb helpers.

https://docs.oracle.com/cd/E19455-01/816-3324/6m9k4vdqa/index.html

gdb does provide some of these:

€ nm -D gdb | grep ps_
0000000000492cc0 T ps_getpid
0000000000187800 T ps_get_thread_area
0000000000492bd0 T ps_lgetfpregs
0000000000492ae0 T ps_lgetregs
0000000000492c50 T ps_lsetfpregs
0000000000492b60 T ps_lsetregs
0000000000492ab0 T ps_pdread
0000000000492ac0 T ps_pdwrite
0000000000492a10 T ps_pglobal_lookup

Samuel

Reply via email to