eclipse-cdt-cloud / cdt-gdb-adapter

CDT GDB Debug Adapter
Eclipse Public License 2.0
28 stars 40 forks source link

Attach to process does not work #244

Closed jonahgraham closed 1 year ago

jonahgraham commented 1 year ago

While there is sort of code in the adapter to support attach (non-remote) use case, it doesn't actually work.

Instead of attaching to the program, it actually kills it!

Key parts of the log:

GDB command: 4 -target-attach 651960
GDB notify async: thread-group-started,id="i1",pid="651960"
GDB result: 4 done
GDB exec async: stopped[...]
GDB command: 6 -exec-run
GDB notify async: thread-group-exited,id="i1"
GDB notify async: thread-group-started,id="i1",pid="652103"

As can be seen, when doing an attach an -exec-run is sent, which is clearly wrong, leading to the pid that user tried to connect to (651960) being terminated and a new process starting (652103)

full DAP + MI trace ``` From client: initialize({"clientID":"vscode","clientName":"Visual Studio Code","adapterID":"gdb","pathFormat":"path","linesStartAt1":true,"columnsStartAt1":true,"supportsVariableType":true,"supportsVariablePaging":true,"supportsRunInTerminalRequest":true,"locale":"en-gb","supportsProgressReporting":true,"supportsInvalidatedEvent":true,"supportsMemoryReferences":true,"supportsArgsCanBeInterpretedByShell":true,"supportsMemoryEvent":true}) To client: {"seq":0,"type":"response","request_seq":1,"command":"initialize","success":true,"body":{"supportsConfigurationDoneRequest":true,"supportsSetVariable":true,"supportsConditionalBreakpoints":true,"supportsHitConditionalBreakpoints":true,"supportsLogPoints":true,"supportsFunctionBreakpoints":true,"supportsDisassembleRequest":true,"supportsReadMemoryRequest":true,"supportsWriteMemoryRequest":true}} From client: attach({"type":"gdb","request":"attach","name":"cdt attach","program":"/scratch/debug/git/cdt-gdb-adapter/src/integration-tests/test-programs/empty","processId":"651960","verbose":true,"openGdbConsole":false,"__configurationTarget":6,"__sessionId":"588f7da0-968a-4548-8c9a-d47ba9caec06"}) GDB notify async: thread-group-added,id="i1" To client: {"seq":0,"type":"event","event":"output","body":{"category":"stdout","output":"GNU gdb (Ubuntu 10.2-0ubuntu1~20.04~1) 10.2\n"}} GNU gdb (Ubuntu 10.2-0ubuntu1~20.04~1) 10.2 To client: {"seq":0,"type":"event","event":"output","body":{"category":"stdout","output":"Copyright (C) 2021 Free Software Foundation, Inc.\n"}} Copyright (C) 2021 Free Software Foundation, Inc. To client: {"seq":0,"type":"event","event":"output","body":{"category":"stdout","output":"License GPLv3+: GNU GPL version 3 or later \nThis is free software: you are free to change and redistribute it.\nThere is NO WARRANTY, to the extent permitted by law."}} License GPLv3+: GNU GPL version 3 or later This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.To client: {"seq":0,"type":"event","event":"output","body":{"category":"stdout","output":"\nType \"show copying\" and \"show warranty\" for details.\n"}} Type "show copying" and "show warranty" for details. To client: {"seq":0,"type":"event","event":"output","body":{"category":"stdout","output":"This GDB was configured as \"x86_64-linux-gnu\".\n"}} This GDB was configured as "x86_64-linux-gnu". To client: {"seq":0,"type":"event","event":"output","body":{"category":"stdout","output":"Type \"show configuration\" for configuration details.\n"}} Type "show configuration" for configuration details. To client: {"seq":0,"type":"event","event":"output","body":{"category":"stdout","output":"For bug reporting instructions, please see:\n"}} For bug reporting instructions, please see: To client: {"seq":0,"type":"event","event":"output","body":{"category":"stdout","output":".\n"}} . To client: {"seq":0,"type":"event","event":"output","body":{"category":"stdout","output":"Find the GDB manual and other documentation resources online at:\n ."}} Find the GDB manual and other documentation resources online at: .To client: {"seq":0,"type":"event","event":"output","body":{"category":"stdout","output":"\n\n"}} To client: {"seq":0,"type":"event","event":"output","body":{"category":"stdout","output":"For help, type \"help\".\n"}} For help, type "help". To client: {"seq":0,"type":"event","event":"output","body":{"category":"stdout","output":"Type \"apropos word\" to search for commands related to \"word\".\n"}} Type "apropos word" to search for commands related to "word". GDB notify async: cmd-param-changed,param="auto-load safe-path",value="/" GDB unhandled notify: cmd-param-changed: {"param":"auto-load safe-path","value":"/"} GDB command: 0 -gdb-set non-stop off GDB result: 0 done GDB command: 1 -gdb-set mi-async on GDB result: 1 done GDB command: 2 -file-exec-and-symbols "/scratch/debug/git/cdt-gdb-adapter/src/integration-tests/test-programs/empty" GDB result: 2 done GDB command: 3 -enable-pretty-printing GDB result: 3 done GDB command: 4 -target-attach 651960 GDB notify async: thread-group-started,id="i1",pid="651960" GDB notify async: thread-created,id="1",group-id="i1" GDB result: 4 done GDB notify async: library-loaded,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="0x00007f284a4ef630",to="0x00007f284a66427d"}] To client: {"seq":0,"type":"event","event":"output","body":{"category":"console","output":"attached to process 651960"}} attached to process 651960 To client: {"seq":0,"type":"event","event":"initialized"} To client: {"seq":0,"type":"response","request_seq":2,"command":"attach","success":true} GDB notify async: library-loaded,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="0x00007f284a6de100",to="0x00007f284a700684"}] From client: setFunctionBreakpoints({"breakpoints":[]}) GDB command: 5 -break-list To client: {"seq":0,"type":"event","event":"output","body":{"category":"stdout","output":"0x00007f284a5aa1b4 in __GI___clock_nanosleep (clock_id=, clock_id@entry=0, flags=flags@entry=0, req=req@entry=0x7ffda68690c0, rem=rem@entry=0x7ffda68690c0) at ../sysdeps/unix/sysv/linux/clock_nanosleep.c:78\n"}} 0x00007f284a5aa1b4 in __GI___clock_nanosleep (clock_id=, clock_id@entry=0, flags=flags@entry=0, req=req@entry=0x7ffda68690c0, rem=rem@entry=0x7ffda68690c0) at ../sysdeps/unix/sysv/linux/clock_nanosleep.c:78 To client: {"seq":0,"type":"event","event":"output","body":{"category":"log","output":"78\t../sysdeps/unix/sysv/linux/clock_nanosleep.c: No such file or directory.\n"}} 78 ../sysdeps/unix/sysv/linux/clock_nanosleep.c: No such file or directory. GDB exec async: stopped,frame={addr="0x00007f284a5aa1b4",func="__GI___clock_nanosleep",args=[{name="clock_id",value=""},{name="clock_id@entry",value="0"},{name="flags",value="0"},{name="flags@entry",value="0"},{name="req",value="0x7ffda68690c0"},{name="req@entry",value="0x7ffda68690c0"},{name="rem",value="0x7ffda68690c0"},{name="rem@entry",value="0x7ffda68690c0"}],file="../sysdeps/unix/sysv/linux/clock_nanosleep.c",fullname="/build/glibc-SzIz7B/glibc-2.31/time/../sysdeps/unix/sysv/linux/clock_nanosleep.c",line="78",arch="i386:x86-64"},thread-id="1",stopped-threads="all",core="1" GDB result: 5 done,BreakpointTable={nr_rows="0",nr_cols="6",hdr=[{width="7",alignment="-1",col_name="number",colhdr="Num"},{width="14",alignment="-1",col_name="type",colhdr="Type"},{width="4",alignment="-1",col_name="disp",colhdr="Disp"},{width="3",alignment="-1",col_name="enabled",colhdr="Enb"},{width="10",alignment="-1",col_name="addr",colhdr="Address"},{width="40",alignment="2",col_name="what",colhdr="What"}],body=[]} To client: {"seq":0,"type":"response","request_seq":3,"command":"setFunctionBreakpoints","success":true,"body":{"breakpoints":[]}} From client: configurationDone(undefined) GDB command: 6 -exec-run GDB notify async: thread-exited,id="1",group-id="i1" GDB notify async: thread-group-exited,id="i1" GDB notify async: library-unloaded,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",thread-group="i1" GDB unhandled notify: library-unloaded: {"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","thread-group":"i1"} GDB notify async: library-unloaded,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",thread-group="i1" GDB unhandled notify: library-unloaded: {"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","thread-group":"i1"} GDB notify async: thread-group-started,id="i1",pid="652103" GDB notify async: thread-created,id="1",group-id="i1" GDB notify async: library-loaded,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="0x00007ffff7fd0100",to="0x00007ffff7ff2684"}] GDB result: 6 running GDB exec async: running,thread-id="all" To client: {"seq":0,"type":"response","request_seq":4,"command":"configurationDone","success":true} To client: {"seq":0,"type":"event","event":"output","body":{"category":"stdout","output":"[Switching to thread 1 (process 652103)](running)\n"}} [Switching to thread 1 (process 652103)](running) GDB notify async: thread-selected,id="1" GDB notify async: library-loaded,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="0x00007ffff7ddd630",to="0x00007ffff7f5227d"}] From client: threads(undefined) To client: {"seq":0,"type":"response","request_seq":5,"command":"threads","success":true,"body":{"threads":[{"id":1,"name":"1","running":true}]}} ```