Is there a way in gdb to retrieve (not print) the value of options like logging file, logging redirect, etc.? Why do they provide a set command but no get command?
Why do they provide a set command but no get command?
The GDB manual covers this. The get command is usually called show, but sometimes info.
Related
I need to disassemble some C code, but I want to also show the source lines mixed in with the assembly code. The issue I have is that I'm using gdb through the MI interface, which calls disassemble (or equivalent, perhaps -data-disassemble?), and I have no control over the options sent with the command. If I did have access to the command, I could probably just use
-data-disassemble ... -- 1.
I've tried making a user-defined command, e.g.:
define dis
disassemble /s
end
but I don't know how to force using that command through gdb/mi. I also tried making an alias, but it creates a naming conflict ("Alias disassemble is the name of an existing command") and probably wouldn't work anyway because of the MI connection.
I'd like to just add a line to my .gdbinit file that forces the /s option to be a default for disassemble, but I can't find any documentation that shows how this can be done.
As a side note, I'm trying to accomplish this in MSVC 2019, and I can sort of do it manually using the instructions from Microsoft's MIEngine custom command doc. But this doesn't go through the usual gdb/mi interface, and just dumps text into the Command Window. I was able to set disassembly-flavor intel, which works in changing the assembly into Intel format, so it seems like what I want to accomplish is at least plausible.
I would like to write a bat script which call gdb. I want to use script variables in debugging session (like paths, variable names etc.) For example name and location of the config, address ranges to dump or even command.
Is there easy way to do that? I know that there are gdb scripts but I'm not sure how to do that in easy way.
I see that I can access to script variables with "environment" specifier but I can't use it in other way than show and modify this data.
Without considering the sense of this example I would like to have behavior like below.
Bat script:
SET MY_COMMAND=run
SET MY_COMMAND2=quit
SET MY_FUNCTION=main
:: GDB CALL ??
And expected gdb behavior:
break MY_FUNCTION
MY_COMMAND
MY_COMMAND2
Maybe this will be solution for you:
~/.gdbinit
You can put gdb commands there, and whenever gdb is started it will execute them.
Well, in fact, in your case it would be easier to use another approach:
--command=FILE
I would like to assign the "info sharedlibrary" value to a variable in user define function.
Such as,
define customFunction
set $i = info sharedlibrary
end
But it seems impossible in gdb
And also i cannot use python script too...
Is there any way to do this??
Thank you
ps. I trying to do this because i want to print only selected library's instructions.
You don't mention why you can't use a Python function. That's by far the simplest way to program gdb.
However, if you really must do it, and really must avoid Python, there is a way. It's gross! But it does work. It's like this:
Use the various set logging commands to redirect output to a temporary file.
Invoke the command you want.
Use set logging again to disable logging.
Use the shell command to run sed or perl or what-have-you on this temporary file to turn it into a sequence of gdb commands, say commands to set a variable, or commands to print exactly the output you want.
source the resulting file
I would like to know if it is possible to build tcl scripts debugger using Tcl Library API and/or Tcl internal interfaces (I mean if they contain sufficient data to do so). I've noticed that existing tcl debuggers instrument tcl scripts and work with this additional layer. My idea was to use Tcl_CreateObjTrace to trace every evaluated command and use it as a point to retrive callstack, locals etc. Problem is that it seems that not every information is accessible from API at a time of evaluation. For example I would like to know which line is currently evaluated but Interp has such info only for top evaluations (iPtr->cmdFramePtr->line is empty for procedures' bodies). Anyone has tried such approach? Does it make any sense? Maybe should I look into hashed entries in Interp? Any clues and opinions would be appreciated (the best for Tcl 8.5).
Your best bet for a non-intrusive debugging system might be to try using an execution step trace (called for each command called during the execution of the command to which the trace is attached) with info frame to actually get the information. Here's a simple version, attaching to source so that you can watch an entire script:
proc traceinfo args {
puts [dict get [info frame -2] cmd]
}
trace add execution source enterstep traceinfo
source yourscript.tcl
Be prepared for plenty of output. The dictionary out of info frame can have all sorts of relevant entries, such as information about what the line number of the command is and what the source file is; the cmd entry is the unsubstituted source for the command called (if you want the substituted version, see the relevant arguments to the trace callback, traceinfo above).
I would like to redirect the output of the Fabric command
print local("git add .")
so that I make sure that everything is working properly. Is there a way to pipe the results of this command to the console? Thanks!
You should already see the output of the command in the console since that's the default behaviour. If you need to customize it, please have a look at the managing output documentation section.
Besides this, there's an ongoing effort to use the logging module (issue #57) that should provide more options like logging to a file, but that hasn't been merged into the trunk branch yet.