* reference environment variables from gdb scripts
@ 2007-08-23 21:19 rockwellkc
2007-08-24 8:58 ` Jan Kratochvil
0 siblings, 1 reply; 11+ messages in thread
From: rockwellkc @ 2007-08-23 21:19 UTC (permalink / raw)
To: gdb
Is 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
--
View this message in context: http://www.nabble.com/reference-environment-variables-from-gdb-scripts-tf4320152.html#a12302351
Sent from the Sourceware - gdb list mailing list archive at Nabble.com.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: reference environment variables from gdb scripts
2007-08-23 21:19 reference environment variables from gdb scripts rockwellkc
@ 2007-08-24 8:58 ` Jan Kratochvil
2007-08-24 16:38 ` Sheng-Liang Song
0 siblings, 1 reply; 11+ messages in thread
From: Jan Kratochvil @ 2007-08-24 8:58 UTC (permalink / raw)
To: rockwellkc; +Cc: gdb
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
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: reference environment variables from gdb scripts
2007-08-24 8:58 ` Jan Kratochvil
@ 2007-08-24 16:38 ` Sheng-Liang Song
2007-08-24 17:30 ` Eli Zaretskii
0 siblings, 1 reply; 11+ messages in thread
From: Sheng-Liang Song @ 2007-08-24 16:38 UTC (permalink / raw)
To: Jan Kratochvil, rockwellkc, gdb
Hi,
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
>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: reference environment variables from gdb scripts
2007-08-24 16:38 ` Sheng-Liang Song
@ 2007-08-24 17:30 ` Eli Zaretskii
2007-08-24 18:29 ` Sheng-Liang Song
0 siblings, 1 reply; 11+ messages in thread
From: Eli Zaretskii @ 2007-08-24 17:30 UTC (permalink / raw)
To: Sheng-Liang Song; +Cc: jan.kratochvil, koling, gdb
> Date: Fri, 24 Aug 2007 09:37:25 -0700
> From: Sheng-Liang Song <ssl@baymicrosystems.com>
>
> BTW, Is there a gdb script functional document?
The GDB scripting commands are documented in the GDB user manual. See
the node "Sequences".
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: reference environment variables from gdb scripts
2007-08-24 17:30 ` Eli Zaretskii
@ 2007-08-24 18:29 ` Sheng-Liang Song
2007-08-25 9:58 ` Eli Zaretskii
0 siblings, 1 reply; 11+ messages in thread
From: Sheng-Liang Song @ 2007-08-24 18:29 UTC (permalink / raw)
To: Eli Zaretskii, gdb; +Cc: jan.kratochvil, koling
Eli Zaretskii wrote:
>> Date: Fri, 24 Aug 2007 09:37:25 -0700
>> From: Sheng-Liang Song <ssl@baymicrosystems.com>
>>
>> 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
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: reference environment variables from gdb scripts
2007-08-24 18:29 ` Sheng-Liang Song
@ 2007-08-25 9:58 ` Eli Zaretskii
2007-08-27 18:30 ` reference environment variables from gdb scripts (gdb and unix pipe) Sheng-Liang Song
0 siblings, 1 reply; 11+ messages in thread
From: Eli Zaretskii @ 2007-08-25 9:58 UTC (permalink / raw)
To: Sheng-Liang Song; +Cc: gdb, jan.kratochvil, koling
> Date: Fri, 24 Aug 2007 11:26:18 -0700
> From: Sheng-Liang Song <ssl@baymicrosystems.com>
> CC: jan.kratochvil@redhat.com, koling@kchang.net
>
> 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.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: reference environment variables from gdb scripts (gdb and unix pipe)
2007-08-25 9:58 ` Eli Zaretskii
@ 2007-08-27 18:30 ` Sheng-Liang Song
2007-08-28 21:03 ` Jim Blandy
0 siblings, 1 reply; 11+ messages in thread
From: Sheng-Liang Song @ 2007-08-27 18:30 UTC (permalink / raw)
To: Eli Zaretskii, gdb; +Cc: jan.kratochvil, koling
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@baymicrosystems.com>
>> CC: jan.kratochvil@redhat.com, koling@kchang.net
>>
>> 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.
>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: reference environment variables from gdb scripts (gdb and unix pipe)
2007-08-27 18:30 ` reference environment variables from gdb scripts (gdb and unix pipe) Sheng-Liang Song
@ 2007-08-28 21:03 ` Jim Blandy
2007-08-28 21:08 ` GDB Tool Chains McGuerty, Jay S.
0 siblings, 1 reply; 11+ messages in thread
From: Jim Blandy @ 2007-08-28 21:03 UTC (permalink / raw)
To: Sheng-Liang Song; +Cc: Eli Zaretskii, gdb, jan.kratochvil, koling
Sheng-Liang Song <ssl@baymicrosystems.com> 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.
^ permalink raw reply [flat|nested] 11+ messages in thread
* GDB Tool Chains
2007-08-28 21:03 ` Jim Blandy
@ 2007-08-28 21:08 ` McGuerty, Jay S.
2007-08-28 21:56 ` Peter Toft
2007-08-28 21:59 ` Jim Blandy
0 siblings, 2 replies; 11+ messages in thread
From: McGuerty, Jay S. @ 2007-08-28 21:08 UTC (permalink / raw)
To: Jim Blandy; +Cc: gdb
This is a rookie question but here goes.....
Is there a list of available tool chains for GDB anywhere?
Jay
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: GDB Tool Chains
2007-08-28 21:08 ` GDB Tool Chains McGuerty, Jay S.
@ 2007-08-28 21:56 ` Peter Toft
2007-08-28 21:59 ` Jim Blandy
1 sibling, 0 replies; 11+ messages in thread
From: Peter Toft @ 2007-08-28 21:56 UTC (permalink / raw)
To: gdb
[-- Attachment #1: Type: TEXT/PLAIN, Size: 339 bytes --]
On 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@linuxbog.dk] http://petertoft.dk
Følg min Linux-blog på http://www.version2.dk/blogs/petertoft
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: GDB Tool Chains
2007-08-28 21:08 ` GDB Tool Chains McGuerty, Jay S.
2007-08-28 21:56 ` Peter Toft
@ 2007-08-28 21:59 ` Jim Blandy
1 sibling, 0 replies; 11+ messages in thread
From: Jim Blandy @ 2007-08-28 21:59 UTC (permalink / raw)
To: McGuerty, Jay S.; +Cc: gdb
"McGuerty, Jay S." <JAY.S.MCGUERTY@saic.com> 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.)
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2007-08-28 21:59 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-08-23 21:19 reference environment variables from gdb scripts rockwellkc
2007-08-24 8:58 ` Jan Kratochvil
2007-08-24 16:38 ` Sheng-Liang Song
2007-08-24 17:30 ` Eli Zaretskii
2007-08-24 18:29 ` Sheng-Liang Song
2007-08-25 9:58 ` Eli Zaretskii
2007-08-27 18:30 ` reference environment variables from gdb scripts (gdb and unix pipe) Sheng-Liang Song
2007-08-28 21:03 ` Jim Blandy
2007-08-28 21:08 ` GDB Tool Chains McGuerty, Jay S.
2007-08-28 21:56 ` Peter Toft
2007-08-28 21:59 ` Jim Blandy
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox