Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MI Parser only handles async-record with at least one optional result #339

Closed
brownts opened this issue Apr 9, 2022 · 0 comments · Fixed by #340
Closed

MI Parser only handles async-record with at least one optional result #339

brownts opened this issue Apr 9, 2022 · 0 comments · Fixed by #340
Assignees
Labels

Comments

@brownts
Copy link
Collaborator

brownts commented Apr 9, 2022

I was testing this extension's "Attach to a local process" functionality on Windows and noticed that this didn't work as expected, and in fact it appeared the debug adapter was crashing. With further investigation, I tracked this down to a difference in the gdb behavior between the Windows version and the Linux version I was also using. I've included GDB/MI dumps from running a typical attach from the command line, on both Windows and Linux, to show typical output from the debugger.

Windows GDB/MI Attach to Local Process

Click to expand...
C:\> gdb --interpreter=mi2 -p 7740
=thread-group-added,id="i1"
~"GNU gdb (GDB for MinGW-W64 x86_64, built by Brecht Sanders) 10.2\n"
~"Copyright (C) 2021 Free Software Foundation, Inc.\n"
~"License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>\nThis is free software: you are free to change and redistribute it.\nThere is NO WARRANTY, to the extent permitted by law."
~"\nType \"show copying\" and \"show warranty\" for details.\n"
~"This GDB was configured as \"x86_64-w64-mingw32\".\n"
~"Type \"show configuration\" for configuration details.\n"
~"For bug reporting instructions, please see:\n"
~"<https://www.gnu.org/software/gdb/bugs/>.\n"
~"Find the GDB manual and other documentation resources online at:\n    <http://www.gnu.org/software/gdb/documentation/>."
~"\n\n"
~"For help, type \"help\".\n"
~"Type \"apropos word\" to search for commands related to \"word\".\n"
~"Attaching to process 7740\n"
=thread-group-started,id="i1",pid="7740"
=thread-created,id="1",group-id="i1"
=thread-created,id="2",group-id="i1"
~"[New Thread 7740.0x15ac]\n"
~"Reading symbols from c:\\git\\hello_world_exe\\hello_world-gcc.exe...\n"
=library-loaded,id="C:\\Windows\\SYSTEM32\\ntdll.dll",target-name="C:\\Windows\\SYSTEM32\\ntdll.dll",host-name="C:\\Windows\\SYSTEM32\\ntdll.dll",symbols-loaded="0",thread-group="i1",ranges=[{from="0x00007fff8ef71000",to="0x00007fff8f164544"}]
=library-loaded,id="C:\\Windows\\System32\\kernel32.dll",target-name="C:\\Windows\\System32\\kernel32.dll",host-name="C:\\Windows\\System32\\kernel32.dll",symbols-loaded="0",thread-group="i1",ranges=[{from="0x00007fff8ed81000",to="0x00007fff8ee3d30c"}]
=library-loaded,id="C:\\Windows\\System32\\KernelBase.dll",target-name="C:\\Windows\\System32\\KernelBase.dll",host-name="C:\\Windows\\System32\\KernelBase.dll",symbols-loaded="0",thread-group="i1",ranges=[{from="0x00007fff8cd01000",to="0x00007fff8cfc7abc"}]
=library-loaded,id="C:\\Windows\\System32\\msvcrt.dll",target-name="C:\\Windows\\System32\\msvcrt.dll",host-name="C:\\Windows\\System32\\msvcrt.dll",symbols-loaded="0",thread-group="i1",ranges=[{from="0x00007fff8d8a1000",to="0x00007fff8d93d4a8"}]
*stopped
(gdb)

Linux GDB/MI Attach to Local Process

Click to expand...
~/> gdb --interpreter=mi2 -p 5083
=thread-group-added,id="i1"
~"GNU gdb (Ubuntu 9.2-0ubuntu1~20.04.1) 9.2\n"
~"Copyright (C) 2020 Free Software Foundation, Inc.\n"
~"License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>\nThis is free software: you are free to change and redistribute it.\nThere is NO WARRANTY, to the extent permitted by law."
~"\nType \"show copying\" and \"show warranty\" for details.\n"
~"This GDB was configured as \"x86_64-linux-gnu\".\n"
~"Type \"show configuration\" for configuration details.\n"
~"For bug reporting instructions, please see:\n"
~"<http://www.gnu.org/software/gdb/bugs/>.\n"
~"Find the GDB manual and other documentation resources online at:\n    <http://www.gnu.org/software/gdb/documentation/>."
~"\n\n"
~"For help, type \"help\".\n"
~"Type \"apropos word\" to search for commands related to \"word\".\n"
~"Attaching to process 5083\n"
=thread-group-started,id="i1",pid="5083"
=thread-created,id="1",group-id="i1"
~"Reading symbols from /home/troy/git/hello_world_exe/hello_world-gcc...\n"
=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="0x00007fa908c5f630",to="0x00007fa908dd418d"}]
=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="0x00007fa908e3b100",to="0x00007fa908e5d674"}]
~"Reading symbols from /lib/x86_64-linux-gnu/libc.so.6...\n"
~"Reading symbols from /usr/lib/debug//lib/x86_64-linux-gnu/libc-2.31.so...\n"
~"Reading symbols from /lib64/ld-linux-x86-64.so.2...\n"
~"(No debugging symbols found in /lib64/ld-linux-x86-64.so.2)\n"
~"main () at hello_world.c:6\n"
&"6\thello_world.c: No such file or directory.\n"
*stopped,frame={addr="0x000056429f0ff15d",func="main",args=[],file="hello_world.c",fullname="C:\\usr\\src/hello_world.c",line="6",arch="i386:x86-64"},thread-id="1",stopped-threads="all",core="2"
(gdb)

Investigation

The difference is that on Windows, the exec-async-output does not contain any optional results in this particular instance:

*stopped

The same attach on Linux does contain optional results and doesn't exibit the same problem.

*stopped,frame={addr="0x000056429f0ff15d",func="main",args=[],file="hello_world.c",fullname="C:\\usr\\src/hello_world.c",line="6",arch="i386:x86-64"},thread-id="1",stopped-threads="all",core="2"

Further investigation into the extension's implementation indicates that there is a bug in the parsing such that it will not successfully handle an async-record which does not contain any optional results, and in fact will crash the adapter. The crash is due to attempting to use regex match results that don't exist (because the match didn't actually succeed). The reason the match fails is because the current regex, when attempting to match the async-class, expects to also match the comma separator between the async-class and the optional result. The regex should be updated so that it is not necessary to match this comma separator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant