From cec6cc310a499c8f5659052b70eb0211bccb109f Mon Sep 17 00:00:00 2001 From: Johannes Stoelp Date: Sat, 9 Nov 2024 11:40:55 +0100 Subject: gdb: trace-commands, exec-wrapper --- src/debug/gdb.md | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'src/debug/gdb.md') diff --git a/src/debug/gdb.md b/src/debug/gdb.md index 41d26f7..61bc9dd 100644 --- a/src/debug/gdb.md +++ b/src/debug/gdb.md @@ -258,11 +258,18 @@ thread name on: Truncate log file on each run. off: Append to logfile (default). + set trace-commands + on: Echo comamands executed (good with logging). + off: Do not echo commands executedt (default). + set history filename Change file where to save and restore command history to and from. set history Enable or disable saving of command history. + + set exec-wrapper + Set an exec wrapper which sets up the env and execs the debugee. ``` > Logging options should be configured before logging is turned on. @@ -505,4 +512,34 @@ executed. To workaround that bug one can create a wrapper function which calls end ``` +## Launch debuggee through an exec wrapper +```markdown +> cat test.c +#include +#include + +int main() { + const char* env = getenv("MOOSE"); + printf("$MOOSE=%s\n", env ? env : ""); +} + +> cat test.sh +#!/bin/bash + +echo "running test.sh wapper" +export MOOSE=moose +exec ./test + +> gcc -g -o test test.c + +> gdb test +(gdb) r +$MOOSE= + +(gdb) set exec-wrapper bash test.sh +(gdb) r +running test.sh wapper +$MOOSE=moose +``` + [gdb-convenience-vars]: https://sourceware.org/gdb/onlinedocs/gdb/Convenience-Vars.html#Convenience-Vars -- cgit v1.2.3