Mirror of the gdb mailing list
 help / color / mirror / Atom feed
* bitwise operations on registers
@ 2002-03-10 23:50 Andrew Morton
  2002-03-11  3:04 ` Eli Zaretskii
  0 siblings, 1 reply; 8+ messages in thread
From: Andrew Morton @ 2002-03-10 23:50 UTC (permalink / raw)
  To: gdb

I'm sure I'm doing something silly.

(gdb) p $esp + 4
$15 = (void *) 0xca9c3ea4
(gdb) p $esp & 4
Argument to arithmetic operation not a number or boolean.
(gdb) 

I don't seem to be able to perform the `&' and `|' arithmetic
operators against machine registers.

GNU gdb Red Hat Linux (5.1.1-1)

Thanks.


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

* Re: bitwise operations on registers
  2002-03-10 23:50 bitwise operations on registers Andrew Morton
@ 2002-03-11  3:04 ` Eli Zaretskii
  2002-03-11  7:35   ` Andrew Cagney
  0 siblings, 1 reply; 8+ messages in thread
From: Eli Zaretskii @ 2002-03-11  3:04 UTC (permalink / raw)
  To: Andrew Morton; +Cc: gdb


On Sun, 10 Mar 2002, Andrew Morton wrote:

> (gdb) p $esp & 4
> Argument to arithmetic operation not a number or boolean.
> (gdb) 
> 
> I don't seem to be able to perform the `&' and `|' arithmetic
> operators against machine registers.

"p $eax & 4" works for me.  Doesn't it work for you?

As for $esp, I think GDB knows that it's not a number, so try

  (gdb) p (int)$esp & 4

(I don't know whether the built-in knowledge GDB has about $esp should 
prevent it from working without the cast, though.)


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

* Re: bitwise operations on registers
  2002-03-11  3:04 ` Eli Zaretskii
@ 2002-03-11  7:35   ` Andrew Cagney
  2002-03-11  7:39     ` Daniel Jacobowitz
  0 siblings, 1 reply; 8+ messages in thread
From: Andrew Cagney @ 2002-03-11  7:35 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Andrew Morton, gdb

> On Sun, 10 Mar 2002, Andrew Morton wrote:
> 
> 
>> (gdb) p $esp & 4
>> Argument to arithmetic operation not a number or boolean.
>> (gdb) 
>> 
>> I don't seem to be able to perform the `&' and `|' arithmetic
>> operators against machine registers.
> 
> 
> "p $eax & 4" works for me.  Doesn't it work for you?
> 
> As for $esp, I think GDB knows that it's not a number, so try
> 
>   (gdb) p (int)$esp & 4
> 
> (I don't know whether the built-in knowledge GDB has about $esp should 
> prevent it from working without the cast, though.)

Yes, try:
	(gdb) p (void*)0 & 4
So, this a bug?

Andrew




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

* Re: bitwise operations on registers
  2002-03-11  7:35   ` Andrew Cagney
@ 2002-03-11  7:39     ` Daniel Jacobowitz
  2002-03-14 19:12       ` Andrew Cagney
  0 siblings, 1 reply; 8+ messages in thread
From: Daniel Jacobowitz @ 2002-03-11  7:39 UTC (permalink / raw)
  To: Andrew Cagney; +Cc: Eli Zaretskii, Andrew Morton, gdb

On Mon, Mar 11, 2002 at 10:35:11AM -0500, Andrew Cagney wrote:
> >On Sun, 10 Mar 2002, Andrew Morton wrote:
> >
> >
> >>(gdb) p $esp & 4
> >>Argument to arithmetic operation not a number or boolean.
> >>(gdb) 
> >>
> >>I don't seem to be able to perform the `&' and `|' arithmetic
> >>operators against machine registers.
> >
> >
> >"p $eax & 4" works for me.  Doesn't it work for you?
> >
> >As for $esp, I think GDB knows that it's not a number, so try
> >
> >  (gdb) p (int)$esp & 4
> >
> >(I don't know whether the built-in knowledge GDB has about $esp should 
> >prevent it from working without the cast, though.)
> 
> Yes, try:
> 	(gdb) p (void*)0 & 4
> So, this a bug?

I think so.  C won't let you do it either, but historically we've been
more permissive than C about things that have a clearly defined
meaning, and this does.

-- 
Daniel Jacobowitz                           Carnegie Mellon University
MontaVista Software                         Debian GNU/Linux Developer


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

* Re: bitwise operations on registers
  2002-03-11  7:39     ` Daniel Jacobowitz
@ 2002-03-14 19:12       ` Andrew Cagney
       [not found]         ` <3C9173AD.E2FBA5DA@zip.com.au>
  0 siblings, 1 reply; 8+ messages in thread
From: Andrew Cagney @ 2002-03-14 19:12 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Daniel Jacobowitz, Eli Zaretskii, gdb

Andrew,

Sounds like a bug report is in order (http://sources.redhat.com/gdb/bugs)

Andrew

> On Mon, Mar 11, 2002 at 10:35:11AM -0500, Andrew Cagney wrote:
> 
>> >On Sun, 10 Mar 2002, Andrew Morton wrote:
>> >
>> >
> 
>> >>(gdb) p $esp & 4
>> >>Argument to arithmetic operation not a number or boolean.
>> >>(gdb) 
>> >>
>> >>I don't seem to be able to perform the `&' and `|' arithmetic
>> >>operators against machine registers.
> 
>> >
>> >
>> >"p $eax & 4" works for me.  Doesn't it work for you?
>> >
>> >As for $esp, I think GDB knows that it's not a number, so try
>> >
>> > (gdb) p (int)$esp & 4
>> >
>> >(I don't know whether the built-in knowledge GDB has about $esp should 
>> >prevent it from working without the cast, though.)
> 
>> 
>> Yes, try:
>> (gdb) p (void*)0 & 4
>> So, this a bug?
> 
> 
> I think so.  C won't let you do it either, but historically we've been
> more permissive than C about things that have a clearly defined
> meaning, and this does.
> 
> 



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

* Re: bitwise operations on registers
       [not found]         ` <3C9173AD.E2FBA5DA@zip.com.au>
@ 2002-03-14 21:03           ` Daniel Jacobowitz
  2002-03-27 13:43             ` Andrew Cagney
  0 siblings, 1 reply; 8+ messages in thread
From: Daniel Jacobowitz @ 2002-03-14 21:03 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Andrew Cagney, Eli Zaretskii, gdb

On Thu, Mar 14, 2002 at 08:08:13PM -0800, Andrew Morton wrote:
> Andrew Cagney wrote:
> > 
> > Andrew,
> > 
> > Sounds like a bug report is in order (http://sources.redhat.com/gdb/bugs)
> 
> Done.  Thanks, guys.
> 
> Mind if I ask a little usage question while I'm here?
> 
> The kernel has various funky tricks which I'd like to be
> able to express in the debugger.  For example, the currently-running
> task's controlling structure is always at
> 
> 	*($esp & ~8191).
> 
> So it would be convenient to be able to do
> 
> 	define current ((struct task_struct *)($esp & ~8191))
> 
> then
> 
> (gdb) p current->pid

Can't really do this, but you can at least:
define current
((struct task_struct *)($esp & ~8191))
end

(gdb) current
$33 = <blah>
(gdb) $33->pid


> That's a simple one.  More complex is a representation of
> the kernel's trick of using negative offsetof() to go from
> a doubly-linked-list structure back to the start of its containing
> object.  The list_entry() macro.
> 
> But alas, as far as I know, none of this is possible.
> 
> Any pointers to how one could set about doing all of this?

No generic way to do it, you do have some userdefined function
capability.  As you find specific shortcomings, file bugs :)

For instance: macros that return values would be useful.  offsetof
would be useful.


-- 
Daniel Jacobowitz                           Carnegie Mellon University
MontaVista Software                         Debian GNU/Linux Developer


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

* Re: bitwise operations on registers
  2002-03-14 21:03           ` Daniel Jacobowitz
@ 2002-03-27 13:43             ` Andrew Cagney
  2002-03-27 14:55               ` Daniel Jacobowitz
  0 siblings, 1 reply; 8+ messages in thread
From: Andrew Cagney @ 2002-03-27 13:43 UTC (permalink / raw)
  To: Daniel Jacobowitz, Andrew Morton; +Cc: Eli Zaretskii, gdb

> 
> Can't really do this, but you can at least:
> define current
> ((struct task_struct *)($esp & ~8191))
> end
> 
> (gdb) current
> $33 = <blah>
> (gdb) $33->pid

You've also got:
	(gdb) set $current = ($esp & ~8191)
but that is only evaluated once (If I remember right).

The next step would be to add it to the stop-hook so it is executed 
after every stop.

Andrew




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

* Re: bitwise operations on registers
  2002-03-27 13:43             ` Andrew Cagney
@ 2002-03-27 14:55               ` Daniel Jacobowitz
  0 siblings, 0 replies; 8+ messages in thread
From: Daniel Jacobowitz @ 2002-03-27 14:55 UTC (permalink / raw)
  To: Andrew Cagney; +Cc: Andrew Morton, Eli Zaretskii, gdb

On Wed, Mar 27, 2002 at 04:41:43PM -0500, Andrew Cagney wrote:
> >
> >Can't really do this, but you can at least:
> >define current
> >((struct task_struct *)($esp & ~8191))
> >end
> >
> >(gdb) current
> >$33 = <blah>
> >(gdb) $33->pid
> 
> You've also got:
> 	(gdb) set $current = ($esp & ~8191)
> but that is only evaluated once (If I remember right).
> 
> The next step would be to add it to the stop-hook so it is executed 
> after every stop.

... or hook it up to Jim's new macro expander, perhaps?

-- 
Daniel Jacobowitz                           Carnegie Mellon University
MontaVista Software                         Debian GNU/Linux Developer


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

end of thread, other threads:[~2002-03-27 22:55 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-03-10 23:50 bitwise operations on registers Andrew Morton
2002-03-11  3:04 ` Eli Zaretskii
2002-03-11  7:35   ` Andrew Cagney
2002-03-11  7:39     ` Daniel Jacobowitz
2002-03-14 19:12       ` Andrew Cagney
     [not found]         ` <3C9173AD.E2FBA5DA@zip.com.au>
2002-03-14 21:03           ` Daniel Jacobowitz
2002-03-27 13:43             ` Andrew Cagney
2002-03-27 14:55               ` Daniel Jacobowitz

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