I would like to see how Bash implements command line argument parsing and stepping through the code as it parses some trivial command should be a good way to do that. How do I set this up? Bash is normally run with
./configure
make
which creates a bash
executable in the top level directory of the source code. I wanted to run that executable though GDB but it doesn’t support M1 Macs so I was thinking to do it through VS Code but I don’t know where to start.
2
Answers
(on macOS)
git clone https://git.savannah.gnu.org/git/bash.git
Install the CodeLLDB VS Code extension
Add a launch.json file with these contents (set
args
to the arguments you want to pass to thebash
executable):main()
function) and hit F5 to run the commandTo set up C/C++ debugging on VS Code, create a
.vscode/launch.json
file and fill in the arguments with whatever you need. See the docs here: https://code.visualstudio.com/docs/cpp/launch-json-reference.That being said, VS Code’s C/C++ debugger just hooks into an existing debugger like GDB or LLDB. If GDB can’t debug your program, try LLDB (might require building Bash with LLVM instead of GCC- not 100% sure). If that’s not an option, you might be out of luck with this exact question.
For setup with LLDB, see How to debug in VS Code using lldb?.