GDBMI_thread_info.st
author Jan Vrany <jan.vrany@labware.com>
Thu, 07 Dec 2023 12:33:31 +0000
changeset 322 1b26d0a9560c
parent 272 cdd1c9ad00de
permissions -rw-r--r--
Emit and handle (custom) `-register-changed` notification This commit adds new (custom) asynchronous notification about register value being changed. Standard GDB does not notify MI clients about register value being changed when debugging (for example, by CLI command `set $rax = 1` or via Python's `Value.assign()`). This caused libgdb's register value cache being out of sync. In the past, this was partially worked around by manually emiting the notification on `GDBRegisterWithValue` APIs, but this did not (and could not) handle the case register was changed from GDB command line. To solve this problem, this commit installs a custom Python event handler that emits new GDB/MI notification - `-register-changed` - whenever a register changes after debugee is stopped. This has been enabled by upstream GDB commit 4825fd "gdb/python: implement support for sending custom MI async notifications" On libgdbs side, complete inferior state is invalidated. In theory, one could carefully invalidate only the changed `GDBRegisterWithValue` but in certain cases this could also change the backtrace (for example, if one updates stack pointer) or position in code. So it seems safer to just invalidate everything.

"
jv:libgdbs - GNU Debugger Interface Library
Copyright (C) 2015-now Jan Vrany
Copyright (C) 2022-2023 LabWare

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the 'Software'), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"
"{ Package: 'jv:libgdbs' }"

"{ NameSpace: Smalltalk }"

GDBMICommand subclass:#GDBMI_thread_info
	instanceVariableNames:''
	classVariableNames:''
	poolDictionaries:''
	category:'GDB-Commands-MI'
!

!GDBMI_thread_info class methodsFor:'documentation'!

copyright
"
jv:libgdbs - GNU Debugger Interface Library
Copyright (C) 2015-now Jan Vrany
Copyright (C) 2022-2023 LabWare

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the 'Software'), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"
!

documentation
"
The `-thread-info' Command
--------------------------

Synopsis
........

      -thread-info [ THREAD-ID ]

   Reports information about either a specific thread, if the THREAD-ID
parameter is present, or about all threads.  When printing information
about all threads, also reports the current thread.

{No value for `GDBN'} Command
.............................

The `info thread' command prints the same information about all threads.

Result
......

The result is a list of threads.  The following attributes are defined
for a given thread:

`current'
     This field exists only for the current thread.  It has the value
     `*'.

`id'
     The identifier that {No value for `GDBN'} uses to refer to the
     thread.

`target-id'
     The identifier that the target uses to refer to the thread.

`details'
     Extra information about the thread, in a target-specific format.
     This field is optional.

`name'
     The name of the thread.  If the user specified a name using the
     `thread name' command, then this name is given.  Otherwise, if {No
     value for `GDBN'} can extract the thread name from the target,
     then that name is given.  If {No value for `GDBN'} cannot find the
     thread name, then this field is omitted.

`frame'
     The stack frame currently executing in the thread.

`state'
     The thread's state.  The `state' field may have the following
     values:

    `stopped'
          The thread is stopped.  Frame information is available for
          stopped threads.

    `running'
          The thread is running.  There's no frame information for
          running threads.


`core'
     If {No value for `GDBN'} can find the CPU core on which this
     thread is running, then this field is the core identifier.  This
     field is optional.


Example
.......

     -thread-info
     ^done,threads=[
     {id='2',target-id='Thread 0xb7e14b90 (LWP 21257)',
        frame={level='0',addr='0xffffe410',func='__kernel_vsyscall',
                args=[]},state='running'},
     {id='1',target-id='Thread 0xb7e156b0 (LWP 21254)',
        frame={level='0',addr='0x0804891f',func='foo',
                args=[{name='i',value='10'}],
                file='/tmp/a.c',fullname='/tmp/a.c',line='158'},
                state='running'}],
     current-thread-id='1'
     (gdb)


"
! !

!GDBMI_thread_info methodsFor:'accessing'!

operation
	^ 'thread-info'
! !

!GDBMI_thread_info methodsFor:'accessing-descriptors'!

resultDescription     
    ^ (super resultDescription)
        define:#threads
            as:Array
            of:GDBThreadInfo;
        yourself

    "
    GDBMI_thread_info new resultDescription
    "

    "Created: / 17-09-2014 / 00:00:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 08-03-2015 / 08:20:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified (comment): / 18-03-2015 / 17:05:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!GDBMI_thread_info class methodsFor:'documentation'!

version_HG

    ^ '$Changeset: <not expanded> $'
! !