public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
* bytecode question
@ 2006-04-16 23:16 Nicholas Mc Guire
  2006-04-16 23:33 ` Daniel Jacobowitz
  0 siblings, 1 reply; 2+ messages in thread
From: Nicholas Mc Guire @ 2006-04-16 23:16 UTC (permalink / raw)
  To: gdb



   
HI !

 I'm still fighting with bytecode in gdb tracepoints - wrote up a brute
 froce interpreter for the bytecode and it seems to be doing something
 resonable - just the values finaly collected are plain wrong :)
 collecting memory and registers is working ok (and delivering the right
 values).

Host side:
(gdb) target remote localhost:1234
Remote debugging using localhost:1234
0x400007b0 in ?? ()
(gdb) symbol-file gdbserver/hello
Reading symbols from /root/tracepoints/gdb-6.3-tp2/gdb/gdbserver/hello...done.
(gdb) trace 28
Tracepoint 1 at 0x80483f2: file hello.c, line 28.
(gdb) act
Enter actions for tracepoint 1, one per line.
End with a line saying just "end".
> col junk
> end
(gdb) tstart
(gdb) c
Continuing.

Program exited normally.


 Junk is statically initialized to 40 at line 27 in the test
 case code - but this (and in fact all other variables checked)
 are finaly collected with a value of 00000000.


Target response:
<snip>
tracepoint 1 triggert at 80483f2
found 1 actions for this tp
action length 13, code 26000422000222040322040c27
collecting reg 4 = befef5e4
Trace at befef5e0 (size 4)
dump size 4, data 00000000
bc done

Child exited with retcode = 0



The interpreter loop:

 removed all the cases not needed here - the post is overly long allreadyi
 sorry for that.
 My suspicion is that the way I'm collecting the registers in case 0x26 
 (bytecode register) is collecting the wrong register content in this case
 (value 0x4 is sp on x86) - any idea what could be wrong here ?
 I called set_desired_inferior in the entry function (the tracepoint handler)
 that then called dump_bytecode - must one do anything more to get hold of
 the registers of the application being traced ?

int
dump_bytecode(struct tp_bytecode *bytecode)
{
        int i=0;
        char *bc;
        printf("action length %d, code %s\n",
        bytecode->len,
        bytecode->agent_expression);
        bc=malloc(bytecode->len);
        memset(bc,0,bytecode->len);
        unhexify(bc,bytecode->agent_expression,bytecode->len);

	/* brute force interpreter */
        for(i=0;i<bytecode->len;){
		switch(bc[i++]){
			case 0x02:
				push(pop() + pop());
				break;
			case 0x03:
				{
					unsigned int tmp = pop();
					push(pop() - tmp);
				}
				break;
			case 0x04:
				push(pop() * pop());
				break;
			case 0x0c:
				{
					char dump[256]; 
					char *buf;
					unsigned int size = pop();
					unsigned int addr = pop();
					buf = malloc(size);
					printf("Trace at %x (size %d)\n", 
						addr,size);
					read_inferior_memory(addr,buf,size);
					hexify (dump, buf, sizeof(buf));
					printf("dump size %d, data %s\n",
						size,
						dump);
				}
				break;
			case 0x19:
				{
					unsigned int addr=0;
					unsigned char data[4];
					unsigned int val=0;
					addr=pop();
					read_inferior_memory (addr, data, 4);
					val  = (data [3] << 24);
					val += (data [2] << 16);
					val += (data [1] << 8 );
					val += (data [0] << 0 );
					push(val);
				}
				break;
			case 0x22:
				push(bc[i++]);
				break;
			case 0x23:
				{
					unsigned int tmp = 0;
					tmp  = (bc[i++] << 8);
					tmp += (bc[i++] << 0);
					push(tmp);
				}
				break;
			case 0x24:
				{
					unsigned int tmp = 0;
					tmp  = (bc[i++] << 24);
					tmp += (bc[i++] << 16);
					tmp += (bc[i++] << 8 );
					tmp += (bc[i++] << 0 );
					push(tmp);
				}
				break;
			case 0x26:
				{
					char buf[4]; 
					unsigned int val = 0;
					unsigned int regno = 0;
					regno  = (bc[i++] << 8);
					regno += (bc[i++] << 0);
					//set_desired_inferior (0);
					collect_register(regno, buf); 
					val  = (buf[3] << 24);
					val += (buf[2] << 16);
					val += (buf[1] << 8 );
					val += (buf[0] << 0 );	
					printf("collecting reg %x = %x\n",
						regno,val);
					push(val);
				}
				break;
			case 0x27:
				printf("bc done\n");
				break;
			default:
				printf("invalide opcode %x\n",(unsigned)bc[i-1]);
				break;
		}
	} 

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

* Re: bytecode question
  2006-04-16 23:16 bytecode question Nicholas Mc Guire
@ 2006-04-16 23:33 ` Daniel Jacobowitz
  0 siblings, 0 replies; 2+ messages in thread
From: Daniel Jacobowitz @ 2006-04-16 23:33 UTC (permalink / raw)
  To: Nicholas Mc Guire; +Cc: gdb

On Sun, Apr 16, 2006 at 10:57:35PM +0800, Nicholas Mc Guire wrote:
> tracepoint 1 triggert at 80483f2
> found 1 actions for this tp
> action length 13, code 26000422000222040322040c27
> collecting reg 4 = befef5e4
> Trace at befef5e0 (size 4)
> dump size 4, data 00000000
> bc done
> 
> Child exited with retcode = 0
> 
> 
> 
> The interpreter loop:
> 
>  removed all the cases not needed here - the post is overly long allreadyi
>  sorry for that.
>  My suspicion is that the way I'm collecting the registers in case 0x26 
>  (bytecode register) is collecting the wrong register content in this case
>  (value 0x4 is sp on x86) - any idea what could be wrong here ?
>  I called set_desired_inferior in the entry function (the tracepoint handler)
>  that then called dump_bytecode - must one do anything more to get hold of
>  the registers of the application being traced ?

Why do you think that something is wrong with the register values? 
That looks to me like a sane stack pointer.

I gather from the context that you're doing this in gdbserver.  It
could be anything; you may have stale registers from the last stop.
I recommend understanding how this works in the normal stop/start
case and where the register cache gets updated.

-- 
Daniel Jacobowitz
CodeSourcery

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

end of thread, other threads:[~2006-04-16 15:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-04-16 23:16 bytecode question Nicholas Mc Guire
2006-04-16 23:33 ` Daniel Jacobowitz

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).