Repository navigation
Attach to PID does not process "Initial Commands" before attaching #329
Description
The current method used to attach to a process on the local machine is to specify the PID on the command line to the debugger. However, by doing this, the debugger will attach to the process prior to executing the initial configuration commands (specified in MI2::initCommands). This is inconsistent with remote attach operations (using target-select remote or target-select extended-remote) which only attach to the remote process after the initial configuration commands have been processed.
The problem with attaching prior to processing the initial configuration commands is that there can be spurious errors that occur because of this. For example, if a source path mapping is needed to resolve the source code, when the debugger attaches to the process, it will attempt to locate the source file, but won't be able to find it because the source path mappings commands have not yet been processed. Additionally, this can also lead to errors attempting other commands, such as gdb-set target-async on failing with "Cannot change this setting while the inferior is running".
The below output demonstrates both the source path mapping issue as well as the issue with the failing gdb-set target-async on command. I'd suggest that the current behavior be changed to process the initial configuration commands first, and then issue a "target-attach" command afterwards to attach to the local process.
1-gdb-set target-async on
2-list-features
3-environment-directory "/home/troy/git/hello_world_exe"
4-gdb-set substitute-path "C:\\usr\\src" "/home/troy/git/hello_world_exe/../hello_world_c"
GDB -> App: {"outOfBandRecord":[{"isStream":false,"type":"notify","asyncClass":"thread-group-added","output":[["id","i1"]]}]}
GDB -> App: {"outOfBandRecord":[{"isStream":true,"type":"console","content":"Attaching to process 7801\n"}]}
Attaching to process 7801
GDB -> App: {"outOfBandRecord":[{"isStream":false,"type":"notify","asyncClass":"thread-group-started","output":[["id","i1"],["pid","7801"]]}]}
GDB -> App: {"outOfBandRecord":[{"isStream":false,"type":"notify","asyncClass":"thread-created","output":[["id","1"],["group-id","i1"]]}]}
GDB -> App: {"outOfBandRecord":[{"isStream":true,"type":"console","content":"Reading symbols from /home/troy/git/hello_world_exe/hello_world-gcc..."}]}
Reading symbols from /home/troy/git/hello_world_exe/hello_world-gcc...
GDB -> App: {"outOfBandRecord":[{"isStream":true,"type":"console","content":"done.\n"}]}
done.
GDB -> App: {"outOfBandRecord":[{"isStream":false,"type":"notify","asyncClass":"library-loaded","output":[["id","/lib/x86_64-linux-gnu/libc.so.6"],["target-name","/lib/x86_64-linux-gnu/libc.so.6"],["host-name","/lib/x86_64-linux-gnu/libc.so.6"],["symbols-loaded","0"],["thread-group","i1"],["ranges",[[["from","0x00007f8d2b173360"],["to","0x00007f8d2b2ebafc"]]]]]}]}
GDB -> App: {"outOfBandRecord":[{"isStream":false,"type":"notify","asyncClass":"library-loaded","output":[["id","/lib64/ld-linux-x86-64.so.2"],["target-name","/lib64/ld-linux-x86-64.so.2"],["host-name","/lib64/ld-linux-x86-64.so.2"],["symbols-loaded","0"],["thread-group","i1"],["ranges",[[["from","0x00007f8d2b543f10"],["to","0x00007f8d2b564550"]]]]]}]}
GDB -> App: {"outOfBandRecord":[{"isStream":true,"type":"console","content":"Reading symbols from /lib/x86_64-linux-gnu/libc.so.6..."}]}
Reading symbols from /lib/x86_64-linux-gnu/libc.so.6...
GDB -> App: {"outOfBandRecord":[{"isStream":true,"type":"console","content":"Reading symbols from /usr/lib/debug//lib/x86_64-linux-gnu/libc-2.27.so..."}]}
Reading symbols from /usr/lib/debug//lib/x86_64-linux-gnu/libc-2.27.so...
5-thread-info
GDB -> App: {"outOfBandRecord":[{"isStream":true,"type":"console","content":"done.\n"}]}
done.
GDB -> App: {"outOfBandRecord":[{"isStream":true,"type":"console","content":"done.\n"}]}
done.
GDB -> App: {"outOfBandRecord":[{"isStream":true,"type":"console","content":"Reading symbols from /lib64/ld-linux-x86-64.so.2..."}]}
Reading symbols from /lib64/ld-linux-x86-64.so.2...
GDB -> App: {"outOfBandRecord":[{"isStream":true,"type":"console","content":"Reading symbols from /usr/lib/debug//lib/x86_64-linux-gnu/ld-2.27.so..."}]}
Reading symbols from /usr/lib/debug//lib/x86_64-linux-gnu/ld-2.27.so...
GDB -> App: {"outOfBandRecord":[{"isStream":true,"type":"console","content":"done.\n"}]}
done.
GDB -> App: {"outOfBandRecord":[{"isStream":true,"type":"console","content":"done.\n"}]}
done.
GDB -> App: {"outOfBandRecord":[{"isStream":true,"type":"console","content":"main () at hello_world.c:6\n"}]}
main () at hello_world.c:6
GDB -> App: {"outOfBandRecord":[{"isStream":true,"type":"log","content":"6\thello_world.c: No such file or directory.\n"}]}
6 hello_world.c: No such file or directory.
GDB -> App: {"outOfBandRecord":[{"isStream":false,"type":"exec","asyncClass":"stopped","output":[["frame",[["addr","0x00005615fb5f864a"],["func","main"],["args",[]],["file","hello_world.c"],["fullname","C:\\usr\\src/hello_world.c"],["line","6"]]],["thread-id","1"],["stopped-threads","all"],["core","5"]]}]}
GDB -> App: {"token":1,"outOfBandRecord":[],"resultRecords":{"resultClass":"error","results":[["msg","Cannot change this setting while the inferior is running."]]}}
WARNING: Error executing command 'gdb-set target-async on'
GDB -> App: {"token":2,"outOfBandRecord":[],"resultRecords":{"resultClass":"done","results":[["features",["frozen-varobjs","pending-breakpoints","thread-info","data-read-memory-bytes","breakpoint-notifications","ada-task-info","language-option","info-gdb-mi-command","undefined-command-error-code","exec-run-start-option","python"]]]}}
GDB -> App: {"token":3,"outOfBandRecord":[],"resultRecords":{"resultClass":"done","results":[["source-path","/home/troy/git/hello_world_exe:$cdir:$cwd"]]}}
GDB -> App: {"token":4,"outOfBandRecord":[],"resultRecords":{"resultClass":"done","results":[]}}
GDB -> App: {"token":5,"outOfBandRecord":[],"resultRecords":{"resultClass":"done","results":[["threads",[[["id","1"],["target-id","process 7801"],["name","hello_world-gcc"],["frame",[["level","0"],["addr","0x00005615fb5f864a"],["func","main"],["args",[]],["file","hello_world.c"],["fullname","/home/troy/git/hello_world_c/hello_world.c"],["line","6"]]],["state","stopped"],["core","5"]]]],["current-thread-id","1"]]}}
6-thread-info
GDB -> App: {"token":6,"outOfBandRecord":[],"resultRecords":{"resultClass":"done","results":[["threads",[[["id","1"],["target-id","process 7801"],["name","hello_world-gcc"],["frame",[["level","0"],["addr","0x00005615fb5f864a"],["func","main"],["args",[]],["file","hello_world.c"],["fullname","/home/troy/git/hello_world_c/hello_world.c"],["line","6"]]],["state","stopped"],["core","5"]]]],["current-thread-id","1"]]}}
7-stack-info-depth --thread 1
8-stack-info-depth --thread 1
GDB -> App: {"token":7,"outOfBandRecord":[],"resultRecords":{"resultClass":"done","results":[["depth","1"]]}}
GDB -> App: {"token":8,"outOfBandRecord":[],"resultRecords":{"resultClass":"done","results":[["depth","1"]]}}
9-stack-list-frames --thread 1 0 0
10-stack-list-frames --thread 1 0 0
GDB -> App: {"token":9,"outOfBandRecord":[],"resultRecords":{"resultClass":"done","results":[["stack",[["frame",[["level","0"],["addr","0x00005615fb5f864a"],["func","main"],["file","hello_world.c"],["fullname","/home/troy/git/hello_world_c/hello_world.c"],["line","6"]]]]]]}}
GDB -> App: {"token":10,"outOfBandRecord":[],"resultRecords":{"resultClass":"done","results":[["stack",[["frame",[["level","0"],["addr","0x00005615fb5f864a"],["func","main"],["file","hello_world.c"],["fullname","/home/troy/git/hello_world_c/hello_world.c"],["line","6"]]]]]]}}
11-thread-info
GDB -> App: {"token":11,"outOfBandRecord":[],"resultRecords":{"resultClass":"done","results":[["threads",[[["id","1"],["target-id","process 7801"],["name","hello_world-gcc"],["frame",[["level","0"],["addr","0x00005615fb5f864a"],["func","main"],["args",[]],["file","hello_world.c"],["fullname","/home/troy/git/hello_world_c/hello_world.c"],["line","6"]]],["state","stopped"],["core","5"]]]],["current-thread-id","1"]]}}
12-thread-info
GDB -> App: {"token":12,"outOfBandRecord":[],"resultRecords":{"resultClass":"done","results":[["threads",[[["id","1"],["target-id","process 7801"],["name","hello_world-gcc"],["frame",[["level","0"],["addr","0x00005615fb5f864a"],["func","main"],["args",[]],["file","hello_world.c"],["fullname","/home/troy/git/hello_world_c/hello_world.c"],["line","6"]]],["state","stopped"],["core","5"]]]],["current-thread-id","1"]]}}
13-stack-info-depth --thread 1
GDB -> App: {"token":13,"outOfBandRecord":[],"resultRecords":{"resultClass":"done","results":[["depth","1"]]}}
14-stack-list-frames --thread 1 0 0
GDB -> App: {"token":14,"outOfBandRecord":[],"resultRecords":{"resultClass":"done","results":[["stack",[["frame",[["level","0"],["addr","0x00005615fb5f864a"],["func","main"],["file","hello_world.c"],["fullname","/home/troy/git/hello_world_c/hello_world.c"],["line","6"]]]]]]}}
15-stack-info-depth --thread 1
GDB -> App: {"token":15,"outOfBandRecord":[],"resultRecords":{"resultClass":"done","results":[["depth","1"]]}}
16-stack-list-frames --thread 1 0 0
GDB -> App: {"token":16,"outOfBandRecord":[],"resultRecords":{"resultClass":"done","results":[["stack",[["frame",[["level","0"],["addr","0x00005615fb5f864a"],["func","main"],["file","hello_world.c"],["fullname","/home/troy/git/hello_world_c/hello_world.c"],["line","6"]]]]]]}}
17-stack-list-variables --thread 1 --frame 0 --simple-values
GDB -> App: {"token":17,"outOfBandRecord":[],"resultRecords":{"resultClass":"done","results":[["variables",[]]]}}
Activity
GitMensch commentedon Mar 7, 2022
That is actually a duplicate as we did had that "side-noted" multiple times, but it is the most expressive ones so is the one this is to be tracked under.
To solve it (ideally after #316 - please feel free to comment on this actually untested change) I'd also suggest to change the setup to a plain load, then "attach". I'd welcome a PR (maybe a combined with with the changes of #316? in this case we can close that and use another one instead). Can you self-assign this issue (upper-right corner) to yourself? If not, may I do that?
Note: we only do the
-pif there is no executable specified and some of the initial commands may need an executable loaded already (I'd need to check, don't know).brownts commentedon Mar 7, 2022
Ah, ok, I'm sure I probably missed that it was already documented in one of the previous issues. I happened to stumble upon it and dug into it a bit to understand what has happening. Can you link the other issues to this one if this will be the place where we fix it?
I don't think I can assign this to myself (as I'm not a Collaborator, only Contributor). However, I'd be fine if you assigned this to me.
I'll take a look at #316. Probably makes sense to finish that one first and then start on this one separately. It does looks like there would be some overlap of the affected source, but probably would be good keep the issues separate if possible.
GitMensch commentedon Mar 8, 2022
It was only a "side note" in other issues, when I stumble over one I'll reference this one there.
Thank you for looking into this and #316.
GitMensch commentedon Apr 7, 2022
@brownts is this still open? Looks like "kind of related" to the other nice work you've did.
brownts commentedon Apr 7, 2022
Yes, this is still open. I was trying to push through a few of the other issues and PRs that were already in work. This was going to be the next thing I took a look at. It will require a change to both the MI2::attach and MI2::ssh.
GitMensch commentedon Apr 7, 2022
Thanks for your work on this extension, it helps a lot!
WebFreak001 commentedon Apr 7, 2022
@brownts would you also like to have collaborator access?
Also we might want to move the repository to a GitHub team eventually, so there can be more than one owner on it.
brownts commentedon Apr 7, 2022
Sure, that would be wonderful! 👍