List Info

Thread: Can back trace be stopped from always prints "char*" strings ?




Can back trace be stopped from always prints "char*" strings ?
user name
2008-03-12 04:13:51
Hello,

I have a union being passed to a function. The union is:

typedef union {
   /** This is a pointer to a string name. */
   const char *name_p;
   /** This is the actual 32-bit "raw" integer
name. */
   uint32_t    name_u32;
} Objects_Name;

The problem is the bt command ties to read the string
pointed to by name_p 
how-ever this can be any value if the name_u32 field has
been set. This has 
side effects on the embedded target I am using like killing
the session.

Is there a way to stop the bt accessing the char* data and
just printing the 
pointer value ?

Regards
Chris

Re: Can back trace be stopped from always prints "char*" strings ?
country flaguser name
United States
2008-03-12 07:33:50
On Wed, Mar 12, 2008 at 08:13:51PM +1100, Chris Johns
wrote:
> Is there a way to stop the bt accessing the char* data
and just printing 
> the pointer value ?

I don't think there is.  You might want to look at "set
mem
inaccessible-by-default" and the "mem"
command; that's good for
preventing stray memory reads.

-- 
Daniel Jacobowitz
CodeSourcery

Re: Can back trace be stopped from always prints "char*" strings ?
country flaguser name
United States
2008-03-12 08:59:48
>>>>> "Daniel" == Daniel Jacobowitz
<drowfalse.org> writes:

 Daniel> On Wed, Mar 12, 2008 at 08:13:51PM +1100, Chris
Johns wrote:
 >> Is there a way to stop the bt accessing the char*
data and just
 >> printing the pointer value ?

 Daniel> I don't think there is.  You might want to look
at "set mem
 Daniel> inaccessible-by-default" and the
"mem" command; that's good
 Daniel> for preventing stray memory reads.

Another possibility: if the embedded target dies when this
happens,
that may mean it's getting an addressing error and not
handling that.
The target stub should validate addresses it's given and
reject any
that are out of range.  It also would make sense for it to
intercept
any access errors that make it past those range checks and
turn them
into error messages back to gdb instead.

     paul


Re: Can back trace be stopped from always prints "char*" strings ?
country flaguser name
United States
2008-03-12 09:22:51
On Wed, 2008-03-12 at 08:33 -0400, Daniel Jacobowitz wrote:
> On Wed, Mar 12, 2008 at 08:13:51PM +1100, Chris Johns
wrote:
> > Is there a way to stop the bt accessing the char*
data and just printing 
> > the pointer value ?
> 
> I don't think there is.  You might want to look at
"set mem
> inaccessible-by-default" and the "mem"
command; that's good for
> preventing stray memory reads.

I think the newly introduced "set print
frame-arguments" would help
here. It went in after GDB 6.7 though.
-- 
[]'s
Thiago Jung Bauermann
Software Engineer
IBM Linux Technology Center


Re: Can back trace be stopped from always prints "char*" strings ?
country flaguser name
United States
2008-03-12 14:03:05
On Wed, 2008-03-12 at 20:13 +1100, Chris Johns wrote:
> Hello,
> 
> I have a union being passed to a function. The union
is:
> 
> typedef union {
>    /** This is a pointer to a string name. */
>    const char *name_p;
>    /** This is the actual 32-bit "raw"
integer name. */
>    uint32_t    name_u32;
> } Objects_Name;
> 
> The problem is the bt command ties to read the string
pointed to by name_p 
> how-ever this can be any value if the name_u32 field
has been set. This has 
> side effects on the embedded target I am using like
killing the session.
> 
> Is there a way to stop the bt accessing the char* data
and just printing the 
> pointer value ?

Close...

The closest we have is "set print elements", which
will set a limit
on how many elements of an array (including a string) are
printed
by default.  Unfortunately, zero has been used to mean
"no limit", 
otherwise it would do exactly what you want.

If you "set print elements 1", it will only print
the first byte
of the string -- maybe that will help?

Gosh guys, it would mean changing documented behavior, but
maybe
we ought to consider making zero mean zero, and maybe making
-1
mean "unlimited"...




Re: Can back trace be stopped from always prints "char*" strings ?
user name
2008-03-12 22:56:07
Paul Koning wrote:
>>>>>> "Daniel" == Daniel
Jacobowitz <drowfalse.org> writes:
> 
>  Daniel> On Wed, Mar 12, 2008 at 08:13:51PM +1100,
Chris Johns wrote:
>  >> Is there a way to stop the bt accessing the
char* data and just
>  >> printing the pointer value ?
> 
>  Daniel> I don't think there is.  You might want to
look at "set mem
>  Daniel> inaccessible-by-default" and the
"mem" command; that's good
>  Daniel> for preventing stray memory reads.
> 

This is working so I am able to move forward. Thanks. I
wonder if it is such a 
good idea for GDB to display the string a char* points to by
default when 
handling a union.

> Another possibility: if the embedded target dies when
this happens,
> that may mean it's getting an addressing error and not
handling that.
> The target stub should validate addresses it's given
and reject any
> that are out of range.  It also would make sense for it
to intercept
> any access errors that make it past those range checks
and turn them
> into error messages back to gdb instead.

This may work for a stub running on the target. I have a
gdbserver talking 
over USB to a BDM pod connected to a Coldfire. The gdbserver
knows nothing 
about the target memory map and I am not sure it should need
to know. I think 
the mem command is a good idea. Thank for the idea.

Regards
Chris

[1-6]

about | contact  Other archives ( Real Estate discussion Medical topics )