I'm aware of -file-list-exec-sections, but it seems to be unimplemented in GDB 10.2 (the current as of this time). I wanted a GDB/MI command instead of info proc mappings as I wanted a easier way to parse the results, and also because I was wondering if there any alternatives to the -file-list-exec-sections command as it seems like it vanished.
Use interpreter directive
-interpreter-exec console "info proc mappings "
you will get parsable output (a bit uglier than mi interpreter but does the job )
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.
We can capture macro(%test) executed code with the below snippet
filename mprint 'output-file-name.sas';
options MPRINT MFILE;
%test;
options NOMPRINT NOMFILE;
Is there a way to capture the SAS executed code with MFILE option when we have datasteps/proc calls between the macro calls.
Example:
%test;
data ...
set ...
...
run;
%test2;
proc sort data=...
run;
%test3;
Using some sort of wrapper code to put the above code in a macro and then use MFILE ?
Is there any automated standard approach ? I have to implement the solution at enterprise level.
If you have control over the code itself, then you can do it easily using either:
Alternate logging methods for the entire SAS log (proc printto, altlog startup option)
Wrap the entire code in a macro, then use options mfile
That requires you being able to edit the code, though. Given you've thought of the second, and are asking how, I assume you probably don't have control directly.
If you do not have control over the code but have control over the SAS system (for example, you're a SAS Administrator), then you have a few options, all related to capturing the entire log.
You can, again, use altlog option
Better, though, is the more advanced logging options using the SAS logging facility. This can be used to put pretty detailed logs from the workspace server, or even from base SAS itself if you're in an environment where users run base SAS interactively.
If you are using a SAS Workspace Server (Enterprise Guide, SAS Studio), then the latter option is very easy: you just need to change the Workspace Server's logging level to Debug, and modify the name of the file it outputs to such that you can make use of it (add to the name things like the username).
Do note that options mfile can be overridden by the user, unless you add it to the restricted options table.
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
Are there any generic suggestions for identifying the SAS code / program that is being executed?
My code will execute within a generic macro, so could be called within a Stored Process, another macro, a client SAS program, or even SAS code generated via the mid-tier using IOM. I'd like the highest level identifier possible.. (something that will return the same result if the same program is run again - so process id would not be helpful).
The environment is not windows, so this code is not helpful:
%put %sysget(SAS_EXECFILENAME);
Also, the macro is not necessarily the first program that is called (if it is even a program) - so neither is this code helpful:
proc sql noprint;
select xpath into :progname
from sashelp.vextfl where upcase(xpath) like '%.SAS';
%put &progname;
It sounds to me like you may need to think through how this is to be be used a little more. What if the same user has two sessions open running the same code? Should that use the same file name?
Can you simply make it a requirement of your piece of code that a certain variable must have been specified before your code will run? Otherwise return an error / abort further processing?
To answer your original question though I don't think this is possible.
Is there a way to store the output of the last command in gdb to a string? What I would like to do is store the address information of selected machine level instructions. Redirecting the output is not a solution as it would generate too much output. A simulator would also be a solution, but I'd like to see if it would be possible with gdb as I only want the analysis on a small chunk of code.
So I would need something like this:
(gdb) display/i $pc
(gdb) 1: x/i $pc 0x100000d2e <main+61>: jle 0x100000d02 <main+17
(gdb) set $foo = ??? somehow set this to display line 1
(gdb) call myFunc($foo)
(I excluded the looping controls to keep the example simple)
Or would there be another way of doing this?
Not possible as far as I know, which is kind of surprising considering all the Lisp background of the author :) You'd need either redirection (grep, sed, and awk make wonders on large files, and there's always perl), or your own instruction decoding based on $pc, which I assume is not an option.
Then I don't really understand what you are trying to do. Figure out jump targets? Relocation correctness? What is that you don't know about the code until the runtime? More details can probably point into better direction.
Edit:
Just some links - haven't tried it yet - you might want to play with script-extension setting and see if you can make Python command files work for you:
see Extending GDB and Python in GDB.