code-debug icon indicating copy to clipboard operation
code-debug copied to clipboard

Remote debugging with QEMU -s

Open washraf opened this issue 5 years ago • 11 comments

If submitting a bug please make sure

  • [X] If you are using gdb
    • [X] gdb --version >= 7.7.1
    • [X] it works on the command line with gdb
    • [X] cwd and target are properly set

Screenshots are helpful but not required

I am trying to access a virtual machine running on QEMU, the idea that it works with gdb with console and when I tried using visual studio the extension is failing. My configuration is : { "name": "Debug", "type": "gdb", "request": "attach", "target": "localhost:1234", "remote": true, "gdbpath": "gdb", "cwd": "${workspaceRoot}", "valuesFormatting": "parseText", "autorun": ["set architecture i386:x86-64"], }

It gives this in the debug console. warning: No executable has been specified and target does not support determining executable automatically. Try using the "file" command. 0x00000000f041e122 in ?? () Not implemented stop reason (assuming exception): undefined The target architecture is assumed to be i386:x86-64 No symbol table is loaded. Use the "file" command. No symbol table is loaded. Use the "file" command.

When I try the file it gives no such file or directory?

washraf avatar Jan 08 '20 20:01 washraf

post logs with "printCalls": true, "showDevDebugOutput": true in your launch config pls

WebFreak001 avatar Jan 08 '20 20:01 WebFreak001

1-gdb-set target-async on
2-environment-directory "/home/user/minix"
3-target-select remote localhost:1234
GDB -> App: {"outOfBandRecord":[{"isStream":false,"type":"notify","asyncClass":"thread-group-added","output":[["id","i1"]]}]}
GDB -> App: {"token":1,"outOfBandRecord":[],"resultRecords":{"resultClass":"done","results":[]}}
GDB -> App: {"token":2,"outOfBandRecord":[],"resultRecords":{"resultClass":"done","results":[["source-path","/home/user/minix:$cdir:$cwd"]]}}
GDB -> App: {"outOfBandRecord":[{"isStream":false,"type":"notify","asyncClass":"thread-group-started","output":[["id","i1"],["pid","42000"]]}]}
GDB -> App: {"outOfBandRecord":[{"isStream":true,"type":"log","content":"warning: No executable has been specified and target does not support\ndetermining executable automatically.  Try using the \"file\" command."}]}
warning: No executable has been specified and target does not support
determining executable automatically.  Try using the "file" command.
GDB -> App: {"outOfBandRecord":[{"isStream":true,"type":"log","content":"\n"}]}

GDB -> App: {"outOfBandRecord":[{"isStream":false,"type":"notify","asyncClass":"thread-created","output":[["id","1"],["group-id","i1"]]}]}
GDB -> App: {"outOfBandRecord":[{"isStream":true,"type":"console","content":"0x00000000f041e122 in ?? ()\n"}]}
0x00000000f041e122 in ?? ()
GDB -> App: {"outOfBandRecord":[{"isStream":false,"type":"exec","asyncClass":"stopped","output":[["frame",[["addr","0x00000000f041e122"],["func","??"],["args",[]]]],["thread-id","1"],["stopped-threads","all"]]}]}
Not implemented stop reason (assuming exception): undefined
GDB -> App: {"token":3,"outOfBandRecord":[],"resultRecords":{"resultClass":"connected","results":[]}}
4-break-delete
5-interpreter-exec console "set architecture i386:x86-64"
GDB -> App: {"token":4,"outOfBandRecord":[],"resultRecords":{"resultClass":"done","results":[]}}
GDB -> App: {"outOfBandRecord":[{"isStream":true,"type":"console","content":"The target architecture is assumed to be i386:x86-64\n"}]}
The target architecture is assumed to be i386:x86-64
GDB -> App: {"outOfBandRecord":[{"isStream":false,"type":"notify","asyncClass":"cmd-param-changed","output":[["param","architecture"],["value","i386:x86-64"]]}]}
GDB -> App: {"token":5,"outOfBandRecord":[],"resultRecords":{"resultClass":"done","results":[]}}
6-break-insert -f "/home/user/minix/src/minix/servers/sched/schedule.c:88"
7-break-insert -f "/home/user/minix/src/minix/servers/sched/schedule.c:89"
GDB -> App: {"outOfBandRecord":[{"isStream":true,"type":"log","content":"No symbol table is loaded.  Use the \"file\" command.\n"}]}
No symbol table is loaded.  Use the "file" command.
GDB -> App: {"token":6,"outOfBandRecord":[],"resultRecords":{"resultClass":"done","results":[["bkpt",[["number","1"],["type","breakpoint"],["disp","keep"],["enabled","y"],["addr","<PENDING>"],["pending","/home/user/minix/src/minix/servers/sched/schedule.c:88"],["times","0"],["original-location","/home/user/minix/src/minix/servers/sched/schedule.c:88"]]]]}}
GDB -> App: {"outOfBandRecord":[{"isStream":true,"type":"log","content":"No symbol table is loaded.  Use the \"file\" command.\n"}]}
No symbol table is loaded.  Use the "file" command.
GDB -> App: {"token":7,"outOfBandRecord":[],"resultRecords":{"resultClass":"done","results":[["bkpt",[["number","2"],["type","breakpoint"],["disp","keep"],["enabled","y"],["addr","<PENDING>"],["pending","/home/user/minix/src/minix/servers/sched/schedule.c:89"],["times","0"],["original-location","/home/user/minix/src/minix/servers/sched/schedule.c:89"]]]]}}
8-thread-info
GDB -> App: {"token":8,"outOfBandRecord":[],"resultRecords":{"resultClass":"done","results":[["threads",[[["id","1"],["target-id","Thread 1"],["details","CPU#0 [halted ]"],["frame",[["level","0"],["addr","0x00000000f041e122"],["func","??"],["args",[]]]],["state","stopped"]]]],["current-thread-id","1"]]}}
9-stack-list-frames --thread 1 0 20
GDB -> App: {"token":9,"outOfBandRecord":[],"resultRecords":{"resultClass":"done","results":[["stack",[["frame",[["level","0"],["addr","0x00000000f041e122"],["func","??"]]],["frame",[["level","1"],["addr","0xf0481220f04305fd"],["func","??"]]],["frame",[["level","2"],["addr","0xf0455ff4f047faf0"],["func","??"]]],["frame",[["level","3"],["addr","0x00000000f042fc99"],["func","??"]]],["frame",[["level","4"],["addr","0x000173dff047fdb0"],["func","??"]]],["frame",[["level","5"],["addr","0xe28248be00000000"],["func","??"]]],["frame",[["level","6"],["addr","0xf048582000000002"],["func","??"]]],["frame",[["level","7"],["addr","0x00007c00effffa80"],["func","??"]]],["frame",[["level","8"],["addr","0x0000000000000002"],["func","??"]]],["frame",[["level","9"],["addr","0x00000000effff9a8"],["func","??"]]],["frame",[["level","10"],["addr","0x00000002f041bc97"],["func","??"]]],["frame",[["level","11"],["addr","0xf048582000000000"],["func","??"]]],["frame",[["level","12"],["addr","0xf048582000000000"],["func","??"]]],["frame",[["level","13"],["addr","0x02d23dbe00000000"],["func","??"]]],["frame",[["level","14"],["addr","0x000000002f055a60"],["func","??"]]],["frame",[["level","15"],["addr","0x00000000f042d6a0"],["func","??"]]],["frame",[["level","16"],["addr","0x00007bff00000001"],["func","??"]]],["frame",[["level","17"],["addr","0x0000000000000000"],["func","??"]]]]]]}}
10-exec-continue
GDB -> App: {"token":10,"outOfBandRecord":[],"resultRecords":{"resultClass":"running","results":[]}}
GDB -> App: {"outOfBandRecord":[{"isStream":false,"type":"exec","asyncClass":"running","output":[["thread-id","all"]]}]}
11-thread-info
12-thread-info
GDB -> App: {"token":11,"outOfBandRecord":[],"resultRecords":{"resultClass":"error","results":[["msg","Cannot execute this command while the target is running.\nUse the \"interrupt\" command to stop the target\nand then try again."]]}}
GDB -> App: {"token":12,"outOfBandRecord":[],"resultRecords":{"resultClass":"error","results":[["msg","Cannot execute this command while the target is running.\nUse the \"interrupt\" command to stop the target\nand then try again."]]}}

washraf avatar Jan 08 '20 21:01 washraf

@washraf, I noticed that there is no executable specified in your debug configuration. You might want to try specifying the path to one (with symbols), or add file command(s) to the autorun list to load the debug symbol(s).

irichter avatar Jan 28 '20 01:01 irichter

I am debugging the kernel, The Minix kernel.

washraf avatar Jan 28 '20 02:01 washraf

I am debugging the kernel, The Minix kernel.

@washraf, The executable should probably be the kernel image itself (as loaded either directly by qemu or by the bootloader). If your kernel image has the debug symbols stripped out, You'll want to use an image that has the debug symbols included. I'm not familiar with how to do this on Minix, but I know that Linux enables debug symbols with CONFIG_DEBUG_INFO. I'm successfully debugging FreeBSD with the kernel.full artifact from the build system, which includes the symbols. Be sure to provide an uncompressed unstripped image to gdb (i.e. if using Linux, the correct image would be vmlinux, not vmlinux.bin or vmlinuz). Note that you don't need to boot the uncompressed unstripped version, as long as the version you boot is derived from it. (I boot the stripped image, and load gdb with the unstripped image.)

Keep in mind that if "plain" gdb isn't working, this extension won't work either. If you cannot load the symbols in gdb (by specifying the kernel image with symbols either in the command line or via the file command), you won't be able to do so from this extension.

irichter avatar Jan 28 '20 05:01 irichter

gdb is working, I have tried it and debugged the kernel, I just felt that vs and your extension would give me a better experience. I am also available for an online meeting to discuss it and show you the exact things that I am working with.

washraf avatar Jan 28 '20 14:01 washraf

gdb is working

What command line and instructions are you passing to gdb to connect to load the symbols and connect to qemu?

irichter avatar Jan 28 '20 15:01 irichter

#qemu-system-x86_64 -s -net user,hostfwd=tcp::10022-:22 -net nic -m 2048 -hda minix_x86.img #gdb $ target remote 1234 $ file ../obj.i386/minix/kernel/kernel then I normally debug it.

washraf avatar Jan 28 '20 15:01 washraf

$ file ../obj.i386/minix/kernel/kernel

You need to add this command to the autorun config, e.g.: "autorun": ["set architecture i386:x86-64", "file ../obj.i386/minix/kernel/kernel"]. Make sure to use a path relative to "cwd": "${workspaceRoot}", or use an absolute path.

irichter avatar Jan 28 '20 17:01 irichter

I've also been trying to debug a (custom) kernel in QEMU using this extension but one of its gripes is that it automatically starts the program upon attach. I'd like it to just stayed stopped as it was before attach (-S flag in QEMU).

anirudhb avatar Aug 16 '20 18:08 anirudhb

@anirudhb did you try setting stopAtConnect to true?

brevilo avatar Feb 03 '23 10:02 brevilo