Discussion:
tracemem() output on single line
(too old to reply)
Vladimir Kotal
2011-04-13 12:37:25 UTC
Permalink
Raw Message
Hi all,

Is it somehow possible to use tracemem() (or anything else which is able
to print array of uchar_t's or string) to print stream of bytes in
hexadecimal on single line ?

I'd like to do something like this:

printf("0x");
tracemem(this->oinfo.xxx_id, 32);
printf("A:%-15s ... \n",
this->oinfo.xxx_raddr,
...

where xxx_id and xxx_raddr are of type string.

I'd like the above to produce the output on single line:

0x7FFA403D13DF... A:...


v.
Adam Leventhal
2011-04-13 16:18:43 UTC
Permalink
Raw Message
Hey Vladimir,

Is it somehow possible to use tracemem() (or anything else which is able to
print array of uchar_t's or string) to print stream of bytes in hexadecimal
on single line ?
printf("0x");
tracemem(this->oinfo.xxx_id, 32);
printf("A:%-15s ... \n",
this->oinfo.xxx_raddr,
...
where xxx_id and xxx_raddr are of type string.
0x7FFA403D13DF... A:...
There's nothing particularly convenient, but you could just print out your
array by hand: %02x%02x... To simplify it a little, you could cast it to a
uint64_t *:

printf("%16x%16x", ((uint64_t *)this->oinfo.xxx_id)[0], ((uint64_t
*)this->oinfo.xxx_id)[1]);

I hope that helps.

Adam
--
Adam Leventhal, Delphix
http://dtrace.org/blogs/ahl

275 Middlefield Road, Suite 50
Menlo Park, CA 94025
http://www.delphix.com
Vladimir Kotal
2011-04-14 07:21:32 UTC
Permalink
Raw Message
On 04/13/11 06:18 PM, Adam Leventhal wrote:

<snip>
Post by Adam Leventhal
There's nothing particularly convenient, but you could just print out
your array by hand: %02x%02x... To simplify it a little, you could cast
printf("%16x%16x", ((uint64_t *)this->oinfo.xxx_id)[0], ((uint64_t
*)this->oinfo.xxx_id)[1]);
I hope that helps.
Yes, this should do it for my case. Thanks.

But I also wonder what would you say about e.g. adding new pragma/option
to change the behavior of tracemem().


v.
Adam Leventhal
2011-04-14 16:52:45 UTC
Permalink
Raw Message
But I also wonder what would you say about e.g. adding new pragma/option to
change the behavior of tracemem().
... or a printf() format character that does what you want.

Sounds reasonable.

Adam
--
Adam Leventhal, Delphix
http://dtrace.org/blogs/ahl

275 Middlefield Road, Suite 50
Menlo Park, CA 94025
http://www.delphix.com
Loading...