|
View:
New views
11 Messages
—
Rating Filter:
Alert me
|
|
|
reference environment variables from gdb scriptsIs there a way to reference an environment variable from a gdbscript?
I'm hoping a gdb script command to load different script files based on the current environment variable. I can see these variable using "show env" command. But when I reference them in a file like below, it gives me errors: source $HOME/gdb.scripts Is there a way to do something like this? Thanks |
|
|
Re: reference environment variables from gdb scriptsOn Thu, 23 Aug 2007 23:19:44 +0200, rockwellkc wrote:
> > Is there a way to reference an environment variable from a gdbscript? Unaware. > I'm hoping a gdb script command to load different script files based on the > current environment variable. Set bash function and use the --command parameter? > source $HOME/gdb.scripts $HOME -> ~ and it should work. Regards, Jan |
|
|
Re: reference environment variables from gdb scriptsHi,
I use .cshrc to update the current pointer whenever I login to a 32 or 64 bit machine. If so, I can keep .gdbinit as it is. BTW, Is there a gdb script functional document? Is there a gdb script test vector (or a complete feature checklist) for each gdb release? Thanks, Sheng-Liang .gdbinit source ~/.gdb/current/gdb_stl_utils (ref: http://www.stanford.edu/~afn/gdb_stl_utils/ I try follow the above examples to make some changes for my machine. I feel it is a little bit hard to debug the scripts. If you have more gdb script examples, could you email me? Thanks!) .cshrc if ( -f ~/.gdb/current ) then rm ~/.gdb/current endif ln -s ~/.gdb/`uname -m` ~/.gdb/current /home/ssl/.gdb/i686 /home/ssl/.gdb/x86_64 /home/ssl/.gdb/current -> /home/ssl/.gdb/x86_64 Jan Kratochvil wrote: > On Thu, 23 Aug 2007 23:19:44 +0200, rockwellkc wrote: > >> Is there a way to reference an environment variable from a gdbscript? >> > > Unaware. > > >> I'm hoping a gdb script command to load different script files based on the >> current environment variable. >> > > Set bash function and use the --command parameter? > > >> source $HOME/gdb.scripts >> > > $HOME -> ~ > and it should work. > > > Regards, > Jan > |
|
|
Re: reference environment variables from gdb scripts> Date: Fri, 24 Aug 2007 09:37:25 -0700
> From: Sheng-Liang Song <ssl@...> > > BTW, Is there a gdb script functional document? The GDB scripting commands are documented in the GDB user manual. See the node "Sequences". |
|
|
Re: reference environment variables from gdb scriptsEli Zaretskii wrote:
>> Date: Fri, 24 Aug 2007 09:37:25 -0700 >> From: Sheng-Liang Song <ssl@...> >> >> BTW, Is there a gdb script functional document? >> > > The GDB scripting commands are documented in the GDB user manual. See > the node "Sequences". > Hi, I am looking for a more detail document. (just like this vim script doc with examples): http://vimdoc.sourceforge.net/htmldoc/usr_41.html What is the different between "." and "->" operator in gdb script? (Looks like no difference to me. works the same.) What operators does gdb 6.6 support? Is a gdb script grammar like this one: http://www.nongnu.org/hcb/ $vec->_M_impl STL vector does not have the member var _M_impl. gdb) will report: There is no member or method named _M_impl. How do I check if $vec has the member _M_impl? I would like to write a script like this: if isMember($vec,_M_impl) //do something else //do something else end I have some examples that works on gdb.6.6 only. define adder if $argc == 1 print $arg0 end if $argc == 2 print $arg0 + $arg1 end if $argc == 3 print $arg0 + $arg1 + $arg2 end end define p_stl_vector64 set $vec = ($arg0) set $vec_begin = 0 set $vec_size = $vec->_M_impl->_M_finish - $vec->_M_impl->_M_start set $vec_end = $vec_size - 1 if $argc == 3 set $vec_begin = ($arg1) end if $argc == 3 set $vec_end = ($arg2) end if ($vec_size != 0) set $i = 0 while ($i <= $vec_end) printf "Vector Element %d: ", $i p *($vec->_M_impl->_M_start+$i) set $i++ end end end GNU gdb Red Hat Linux (6.3.0.0-1.132.EL4rh) (DOES NOT WORK!) (gdb) adder 1 2 3 Invalid type combination in equality test. GNU gdb 6.6 (works) (gdb) adder 1 2 3 $1 = 6 |
|
|
Re: reference environment variables from gdb scripts> Date: Fri, 24 Aug 2007 11:26:18 -0700
> From: Sheng-Liang Song <ssl@...> > CC: jan.kratochvil@..., koling@... > > Eli Zaretskii wrote: > > The GDB scripting commands are documented in the GDB user manual. See > > the node "Sequences". > > > > I am looking for a more detail document. There isn't one, because I believe everything is described in the user manual. If you find something that isn't there, please tell. > What is the different between "." and "->" operator in gdb script? > (Looks like no difference to me. works the same.) > > What operators does gdb 6.6 support? This is not specific to scripts. GDB uses operators from the source language, with C/C++ operators being supported more thoroughly than those of other languages. See the node "C Operators" in the manual for C/C++, and similar nodes for other languages in language-specific sections under the node "Supported Languages". In general, anything that is not described in the node "Sequences" and its sub-nodes is not specific to scripting, but is just a feature of normal GDB interaction with the user. > Is a gdb script grammar like this one: > http://www.nongnu.org/hcb/ There's no formal description of the script grammar, since the GDB scripting is just a thin add-on to CLI, the command-line interpreter built into GDB, and CLI is for human interactions, not for programs. Humans don't need a formal grammar to interact with programs, only the format of each command. > $vec->_M_impl > STL vector does not have the member var _M_impl. > gdb) will report: There is no member or method named _M_impl. > > How do I check if $vec has the member _M_impl? I don't think you can, but I don't consider myself a GDB scripting guru. Maybe someone else here will be able to help you. > I would like to write a script like this: > > if isMember($vec,_M_impl) > //do something > else > //do something else > end One way of doing that would be to define within $vec a boolean member that has the value TRUE only if _M_impl is a valid member, then you can check for that boolean flag. Another way is to have a function isMember inside the $vec class (or a global function in your program) that would _return_ such a boolean, then you can use what you wrote above almost verbatim, since GDB can call functions within the debuggee. IOW, whatever you want to test must be already present as data in your program, or else GDB scripting and CLI will not be able to use it in the `if' clause. Admittedly, such a scripting is quite limited, which is why there're plans to add an extension language (Python) to GDB. |
|
|
Re: reference environment variables from gdb scripts (gdb and unix pipe)Hi,
Thanks for the info. gdb has "shell" command to switch to a unix shell. After switch to a unix shell, can I call gdb functions/commands? Does gdb supports "pipe" command? Is there a plan to add a "unix pipe" command to gdb debug prompt? (gdb) p $2 $3 = {<std::_Vector_base<int,std::allocator<int> >> = { _M_impl = {<std::allocator<int>> = {<__gnu_cxx::new_allocator<int>> = {<No data fields>}, <No data fields>}, _M_start = 0x502010, _M_finish = 0x50201c, _M_end_of_storage = 0x50201c}}, <No data fields>} (gdb) p$2 | my_unix_program_to_do_some_data_processing ( a pipe, "|", would be nice to have!) (gdb) if ($?) check the returns end (gdb) shell % gdb p $2 //I lost the control to the gdb environment. (gdb) !my_sell_program_take_a_argument $2 (It would be nice if I can use "!" to execute my shell program.) Thanks, Sheng-Liang Eli Zaretskii wrote: >> Date: Fri, 24 Aug 2007 11:26:18 -0700 >> From: Sheng-Liang Song <ssl@...> >> CC: jan.kratochvil@..., koling@... >> >> Eli Zaretskii wrote: >> >>> The GDB scripting commands are documented in the GDB user manual. See >>> the node "Sequences". >>> >>> >> I am looking for a more detail document. >> > > There isn't one, because I believe everything is described in the user > manual. If you find something that isn't there, please tell. > > >> What is the different between "." and "->" operator in gdb script? >> (Looks like no difference to me. works the same.) >> >> What operators does gdb 6.6 support? >> > > This is not specific to scripts. GDB uses operators from the source > language, with C/C++ operators being supported more thoroughly than > those of other languages. See the node "C Operators" in the manual > for C/C++, and similar nodes for other languages in language-specific > sections under the node "Supported Languages". > > In general, anything that is not described in the node "Sequences" and > its sub-nodes is not specific to scripting, but is just a feature of > normal GDB interaction with the user. > > >> Is a gdb script grammar like this one: >> http://www.nongnu.org/hcb/ >> > > There's no formal description of the script grammar, since the GDB > scripting is just a thin add-on to CLI, the command-line interpreter > built into GDB, and CLI is for human interactions, not for programs. > Humans don't need a formal grammar to interact with programs, only the > format of each command. > > >> $vec->_M_impl >> STL vector does not have the member var _M_impl. >> gdb) will report: There is no member or method named _M_impl. >> >> How do I check if $vec has the member _M_impl? >> > > I don't think you can, but I don't consider myself a GDB scripting > guru. Maybe someone else here will be able to help you. > > >> I would like to write a script like this: >> >> if isMember($vec,_M_impl) >> //do something >> else >> //do something else >> end >> > > One way of doing that would be to define within $vec a boolean member > that has the value TRUE only if _M_impl is a valid member, then you > can check for that boolean flag. Another way is to have a function > isMember inside the $vec class (or a global function in your program) > that would _return_ such a boolean, then you can use what you wrote > above almost verbatim, since GDB can call functions within the > debuggee. > > IOW, whatever you want to test must be already present as data in your > program, or else GDB scripting and CLI will not be able to use it in > the `if' clause. > > Admittedly, such a scripting is quite limited, which is why there're > plans to add an extension language (Python) to GDB. > |
|
|
Re: reference environment variables from gdb scripts (gdb and unix pipe)Sheng-Liang Song <ssl@...> writes: > gdb has "shell" command to switch to a unix shell. > After switch to a unix shell, can I call gdb functions/commands? No; you need to exit the shell before you can give more commands to GDB. > Does gdb supports "pipe" command? Is there a plan to add a "unix pipe" > command to gdb debug prompt? No; we don't have any plans to do so. We're currently planning to add Python as a scripting language to GDB. If that were to happen, the things you mention here could be done in a clean and general way. |
|
|
GDB Tool ChainsThis is a rookie question but here goes..... Is there a list of available tool chains for GDB anywhere? Jay |
|
|
Re: GDB Tool ChainsOn Tue, 28 Aug 2007, McGuerty, Jay S. wrote:
> > This is a rookie question but here goes..... > > Is there a list of available tool chains for GDB anywhere? Tool chains? What do you mean? > > Jay > > Best -- Peter Toft, Ph.D. [pto@...] http://petertoft.dk Følg min Linux-blog på http://www.version2.dk/blogs/petertoft |
|
|
Re: GDB Tool Chains"McGuerty, Jay S." <JAY.S.MCGUERTY@...> writes: > This is a rookie question but here goes..... > > Is there a list of available tool chains for GDB anywhere? No. GDB is most widely tested against the GNU compiler, linker, and debugger. I'd bet it works adequately with the Intel C compiler. I expect it would take work to adapt GDB to understand the DWARF produced by other compilers. (By the way, please don't start new threads by replying to others' messages; doing so makes it difficult for threaded mail readers and web archivers to properly group threads.) |
| Free embeddable forum powered by Nabble | Forum Help |