public inbox for systemtap@sourceware.org
 help / color / mirror / Atom feed
* [Bug translator/14431] New: NULL/invalid char * pretty printed as "<unknown>" string
@ 2012-08-03 10:30 mjw at redhat dot com
  2012-08-04 22:58 ` [Bug translator/14431] " mjw at redhat dot com
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: mjw at redhat dot com @ 2012-08-03 10:30 UTC (permalink / raw)
  To: systemtap

http://sourceware.org/bugzilla/show_bug.cgi?id=14431

             Bug #: 14431
           Summary: NULL/invalid char * pretty printed as "<unknown>"
                    string
           Product: systemtap
           Version: unspecified
            Status: NEW
          Severity: normal
          Priority: P2
         Component: translator
        AssignedTo: systemtap@sourceware.org
        ReportedBy: mjw@redhat.com
    Classification: Unclassified


If you have a char or unsigned char pointer and pretty print it, but it doesn't
actually point to a valid string, then the result is not very useful. char *
and unsigned char * are often used as arbitrary pointers/markers in code, not
just for strings.

Contrived example:

#include <malloc.h>
#include <stddef.h>

struct foobar
{
  char *foo;
  size_t foo_size;
  unsigned char *bar;
  size_t bar_size;
};

static struct foobar *fb;

unsigned char
use ()
{
  if (fb->foo) *fb->foo = 'a';
  return fb->bar_size > 0 ? *fb->bar : 0;
}

int
main (int argc, char **argv)
{
  struct foobar stack;
  fb = &stack;
  fb->foo_size = 42;
  fb->bar_size = 47;
  fb->foo = (char *) calloc (fb->foo_size, 1);
  fb->bar = (unsigned char *) calloc (fb->bar_size, 1);
  fb->bar_size = use (&fb);
  fb->foo = NULL;
  fb->bar = fb->foo + fb->foo_size;
  fb->bar_size = 0;
  return use (&fb);
}

$ gcc -g -o foobar foobar.c 
$ stap -e 'probe process.function("use") { log($fb$) }' -c ./foobar
{.foo="", .foo_size=42, .bar="", .bar_size=47}
{.foo="<unknown>", .foo_size=42, .bar="<unknown>", .bar_size=0}

It would have been convenient if those last two foo/bar pointers were
represented by something different than just "<unknown>".

Maybe "<unknown@0x0>" and "<unknown@0x42>"?

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

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

end of thread, other threads:[~2015-10-21 18:50 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-03 10:30 [Bug translator/14431] New: NULL/invalid char * pretty printed as "<unknown>" string mjw at redhat dot com
2012-08-04 22:58 ` [Bug translator/14431] " mjw at redhat dot com
2012-08-05 20:29 ` jistone at redhat dot com
2012-08-06  8:43 ` [Bug translator/14431] char * always being printed as, possibly INVALID/NULL "<unknown>", string without giving actual address mjw at redhat dot com
2012-08-06 15:32 ` mjw at redhat dot com
2012-08-06 17:24 ` jistone at redhat dot com
2012-08-06 18:59 ` mjw at redhat dot com
2015-10-21 18:50 ` fche at redhat dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).