Mirror of the gdb mailing list
 help / color / mirror / Atom feed
* How to compare $arg0 with string literal?
@ 2015-03-26 16:28 Aleksey Midenkov
  2015-03-26 18:28 ` Doug Evans
  0 siblings, 1 reply; 5+ messages in thread
From: Aleksey Midenkov @ 2015-03-26 16:28 UTC (permalink / raw)
  To: gdb

F.ex.

define logging
    if $argc == 1
        if $arg0 == off
            set logging off
            set logging file gdb.log
        else if $arg0 == stop
            set logging off
        else
            set logging $arg0
        end
    else
        set logging $arg0 $arg1
    end
    show logging
end

When type 'logging off' I get error about no such symbol 'off'...


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: How to compare $arg0 with string literal?
  2015-03-26 16:28 How to compare $arg0 with string literal? Aleksey Midenkov
@ 2015-03-26 18:28 ` Doug Evans
  2015-03-27  6:35   ` Aleksey Midenkov
  0 siblings, 1 reply; 5+ messages in thread
From: Doug Evans @ 2015-03-26 18:28 UTC (permalink / raw)
  To: Aleksey Midenkov; +Cc: gdb

On Thu, Mar 26, 2015 at 9:27 AM, Aleksey Midenkov <midenok@gmail.com> wrote:
> F.ex.
>
> define logging
>     if $argc == 1
>         if $arg0 == off
>             set logging off
>             set logging file gdb.log
>         else if $arg0 == stop
>             set logging off
>         else
>             set logging $arg0
>         end
>     else
>         set logging $arg0 $arg1
>     end
>     show logging
> end
>
> When type 'logging off' I get error about no such symbol 'off'...

Such things are not supported in gdb's own scripting language.
However, with a bit of Python-provided magic ($_streq):

define logging
    if $argc == 1
        if $_streq("$arg0", "off")
            set logging off
            set logging file gdb.log
        else
            if $_streq("$arg0", "stop")
                set logging off
            else
                set logging $arg0
            end
        end
    else
        set logging $arg0 $arg1
    end
    show logging
end

Note that gdb's if/else syntax is a pain.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: How to compare $arg0 with string literal?
  2015-03-26 18:28 ` Doug Evans
@ 2015-03-27  6:35   ` Aleksey Midenkov
  2015-03-27 16:26     ` Doug Evans
  0 siblings, 1 reply; 5+ messages in thread
From: Aleksey Midenkov @ 2015-03-27  6:35 UTC (permalink / raw)
  To: Doug Evans; +Cc: gdb

On Thu, Mar 26, 2015 at 9:28 PM, Doug Evans <dje@google.com> wrote:
> Such things are not supported in gdb's own scripting language.
> However, with a bit of Python-provided magic ($_streq):
>
> define logging
>     if $argc == 1
>         if $_streq("$arg0", "off")
>             set logging off
>             set logging file gdb.log
>         else
>             if $_streq("$arg0", "stop")
>                 set logging off
>             else
>                 set logging $arg0
>             end
>         end
>     else
>         set logging $arg0 $arg1
>     end
>     show logging
> end
>
> Note that gdb's if/else syntax is a pain.

Sure thing, gdb's syntax could be a bit richer... Also, if I get this
error message does that mean that my gdb is not Python-powered?

(gdb)  p $_streq("off", "off")
Invalid data type for function to be called.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: How to compare $arg0 with string literal?
  2015-03-27  6:35   ` Aleksey Midenkov
@ 2015-03-27 16:26     ` Doug Evans
  2015-04-03  9:36       ` Aleksey Midenkov
  0 siblings, 1 reply; 5+ messages in thread
From: Doug Evans @ 2015-03-27 16:26 UTC (permalink / raw)
  To: Aleksey Midenkov; +Cc: gdb

On Thu, Mar 26, 2015 at 11:35 PM, Aleksey Midenkov <midenok@gmail.com> wrote:
> On Thu, Mar 26, 2015 at 9:28 PM, Doug Evans <dje@google.com> wrote:
>> Such things are not supported in gdb's own scripting language.
>> However, with a bit of Python-provided magic ($_streq):
>>
>> define logging
>>     if $argc == 1
>>         if $_streq("$arg0", "off")
>>             set logging off
>>             set logging file gdb.log
>>         else
>>             if $_streq("$arg0", "stop")
>>                 set logging off
>>             else
>>                 set logging $arg0
>>             end
>>         end
>>     else
>>         set logging $arg0 $arg1
>>     end
>>     show logging
>> end
>>
>> Note that gdb's if/else syntax is a pain.
>
> Sure thing, gdb's syntax could be a bit richer... Also, if I get this
> error message does that mean that my gdb is not Python-powered?
>
> (gdb)  p $_streq("off", "off")
> Invalid data type for function to be called.

I'd use "py print 42" or some such as a more direct test of whether
python is present.

btw, which version of gdb are you using?


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: How to compare $arg0 with string literal?
  2015-03-27 16:26     ` Doug Evans
@ 2015-04-03  9:36       ` Aleksey Midenkov
  0 siblings, 0 replies; 5+ messages in thread
From: Aleksey Midenkov @ 2015-04-03  9:36 UTC (permalink / raw)
  To: Doug Evans; +Cc: gdb

On Fri, Mar 27, 2015 at 7:25 PM, Doug Evans <dje@google.com> wrote:
> On Thu, Mar 26, 2015 at 11:35 PM, Aleksey Midenkov <midenok@gmail.com> wrote:
>> On Thu, Mar 26, 2015 at 9:28 PM, Doug Evans <dje@google.com> wrote:
>>> Such things are not supported in gdb's own scripting language.
>>> However, with a bit of Python-provided magic ($_streq):
>>>
>>> define logging
>>>     if $argc == 1
>>>         if $_streq("$arg0", "off")
>>>             set logging off
>>>             set logging file gdb.log
>>>         else
>>>             if $_streq("$arg0", "stop")
>>>                 set logging off
>>>             else
>>>                 set logging $arg0
>>>             end
>>>         end
>>>     else
>>>         set logging $arg0 $arg1
>>>     end
>>>     show logging
>>> end
>>>
>>> Note that gdb's if/else syntax is a pain.
>>
>> Sure thing, gdb's syntax could be a bit richer... Also, if I get this
>> error message does that mean that my gdb is not Python-powered?
>>
>> (gdb)  p $_streq("off", "off")
>> Invalid data type for function to be called.
>
> I'd use "py print 42" or some such as a more direct test of whether
> python is present.
>
> btw, which version of gdb are you using?

That host where this error occurs is always outdated. 7.2-60.el6_4.1
On my local machine is latest version and $_streq() works.
On 7.2 'py print' :

(gdb) py print 42
42
(gdb) py prind 42
  File "<string>", line 1
    prind 42
          ^
SyntaxError: unexpected EOF while parsing
Error while executing Python code.


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-04-03  9:36 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-26 16:28 How to compare $arg0 with string literal? Aleksey Midenkov
2015-03-26 18:28 ` Doug Evans
2015-03-27  6:35   ` Aleksey Midenkov
2015-03-27 16:26     ` Doug Evans
2015-04-03  9:36       ` Aleksey Midenkov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox