public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
* RE: How to build application to run under the ppc simulator?
@ 2003-04-10  7:12 Vermeulen Jan
  0 siblings, 0 replies; 7+ messages in thread
From: Vermeulen Jan @ 2003-04-10  7:12 UTC (permalink / raw)
  To: 'Peter Barada'; +Cc: pbarada, gdb


> >> I can't stepi from the start, I have to run it.  How(actually,
> >> *where*) can I set a breakpoint at the *first* instruction so I can
> >> *then* stepi? 
> >
> >If your only function is 'foo', why not try "break foo" at 
> the gdb command?
> >
> >I just tried it out (same example as you) and it works. I 
> can stepi in the
> >program and see that it jumps to 0x0 after the 'blr' 
> instruction at the end
> >of 'foo' where it segfaults.
> 
> Yeah, I figured out that I can break at main, but I'm trying to figure
> out why:
> 
> (gdb) tar sim
> Connected to the simulator.
> (gdb) load
> (gdb) p $pc
> $1 = 0
> (gdb) x/i 0x0
> 0x0:	Cannot access memory at address 0x0
> (gdb) 
> 
> So the simulater starts out at 0x0 which doesn't make sense.  Where
> does gdb change its mind and figure out where to start?

After you load the program, the simulator has not been started yet.
('info reg' gives 'No selected frame.')

I think that when you do 'run', the simulator will actually be created at
that moment and will load the $pc with the address which was stated in the
linkerscript with the ENTRY(...) directive. Then it'll jump to the simulated
address.

Anyway, this is just from the top of my hat and I'm not a ppc-sim expert
(a.k.a. coder).

If I'm really struggling with something, I dive into the
gdb-<version>/sim/ppc directory and look at some comments in the code.
 
> BTW, how do I use the 'built-in' serial port in the ppc simulator?

See http://sources.redhat.com/psim/manual/ for more info.


Jan

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

* Re: How to build application to run under the ppc simulator?
  2003-04-10  6:02 Vermeulen Jan
@ 2003-04-10  6:08 ` Peter Barada
  0 siblings, 0 replies; 7+ messages in thread
From: Peter Barada @ 2003-04-10  6:08 UTC (permalink / raw)
  To: Jan.Vermeulen; +Cc: pbarada, gdb


>> I can't stepi from the start, I have to run it.  How(actually,
>> *where*) can I set a breakpoint at the *first* instruction so I can
>> *then* stepi? 
>
>If your only function is 'foo', why not try "break foo" at the gdb command?
>
>I just tried it out (same example as you) and it works. I can stepi in the
>program and see that it jumps to 0x0 after the 'blr' instruction at the end
>of 'foo' where it segfaults.

Yeah, I figured out that I can break at main, but I'm trying to figure
out why:

(gdb) tar sim
Connected to the simulator.
(gdb) load
(gdb) p $pc
$1 = 0
(gdb) x/i 0x0
0x0:	Cannot access memory at address 0x0
(gdb) 

So the simulater starts out at 0x0 which doesn't make sense.  Where
does gdb change its mind and figure out where to start?

BTW, how do I use the 'built-in' serial port in the ppc simulator?

-- 
Peter Barada
peter@baradas.org

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

* RE: How to build application to run under the ppc simulator?
@ 2003-04-10  6:02 Vermeulen Jan
  2003-04-10  6:08 ` Peter Barada
  0 siblings, 1 reply; 7+ messages in thread
From: Vermeulen Jan @ 2003-04-10  6:02 UTC (permalink / raw)
  To: 'Peter Barada'; +Cc: peter, gdb, Peter.Barada

Peter,

> >> and it bombs with:
> >> 
> >> >Program terminated with signal SIGSEGV, Segmentation fault.
> >> >The program no longer exists.
> >> >[Switching to process 0]
> >> >(gdb) 
> >
> >This is quite normal, because your program is executed correctly and
> >executes an 'blr' instruction at the end of the main 
> routine. This makes the
> >simulated CPU jump to what's currently in the link register, 
> which can be
> >anything. There it will do crazy things untill it finally 
> segfaults :)
> >
> >If in doubt, just 'stepi' the program, watching the assembly 
> be executed.
> 
> I can't stepi from the start, I have to run it.  How(actually,
> *where*) can I set a breakpoint at the *first* instruction so I can
> *then* stepi? 

If your only function is 'foo', why not try "break foo" at the gdb command?

I just tried it out (same example as you) and it works. I can stepi in the
program and see that it jumps to 0x0 after the 'blr' instruction at the end
of 'foo' where it segfaults.

HTH,
Jan

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

* Re: How to build application to run under the ppc simulator?
  2003-04-09  6:21 Vermeulen Jan
@ 2003-04-09 16:14 ` Peter Barada
  0 siblings, 0 replies; 7+ messages in thread
From: Peter Barada @ 2003-04-09 16:14 UTC (permalink / raw)
  To: Jan.Vermeulen; +Cc: peter, gdb, Peter.Barada


>> and it bombs with:
>> 
>> >Program terminated with signal SIGSEGV, Segmentation fault.
>> >The program no longer exists.
>> >[Switching to process 0]
>> >(gdb) 
>
>This is quite normal, because your program is executed correctly and
>executes an 'blr' instruction at the end of the main routine. This makes the
>simulated CPU jump to what's currently in the link register, which can be
>anything. There it will do crazy things untill it finally segfaults :)
>
>If in doubt, just 'stepi' the program, watching the assembly be executed.

I can't stepi from the start, I have to run it.  How(actually,
*where*) can I set a breakpoint at the *first* instruction so I can
*then* stepi? 

-- 
Peter Barada                                   Peter.Barada@motorola.com
Wizard                                         781-852-2768 (direct)
WaveMark Solutions(wholly owned by Motorola)   781-270-0193 (fax)

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

* RE: How to build application to run under the ppc simulator?
@ 2003-04-09  6:33 Vermeulen Jan
  0 siblings, 0 replies; 7+ messages in thread
From: Vermeulen Jan @ 2003-04-09  6:33 UTC (permalink / raw)
  To: 'Peter Barada', gdb; +Cc: Peter.Barada

Peter,

> I've built a --target=ppc-eabi toolchain, and I've built a tiny little
> test program:
> 
> int a,b;
> int foo(void)
> {
>  a = 0x1234
>  b = 0x5678;
> }
> 

Btw, the simulator always tries to execute main, not a 'foo' program.
You can also adjust the linker script to start at 'foo' instead of main with
the ENTRY directive.

But I'm a bit puzzled: why didn't the compiler complain about not finding a
main-routine?

Can you tell us what versions of gcc, gdb & binutils you used for making
your cross toolchain?

Grz,
Jan

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

* RE: How to build application to run under the ppc simulator?
@ 2003-04-09  6:21 Vermeulen Jan
  2003-04-09 16:14 ` Peter Barada
  0 siblings, 1 reply; 7+ messages in thread
From: Vermeulen Jan @ 2003-04-09  6:21 UTC (permalink / raw)
  To: 'Peter Barada', gdb; +Cc: Peter.Barada

Peter,

> and it bombs with:
> 
> >Program terminated with signal SIGSEGV, Segmentation fault.
> >The program no longer exists.
> >[Switching to process 0]
> >(gdb) 

This is quite normal, because your program is executed correctly and
executes an 'blr' instruction at the end of the main routine. This makes the
simulated CPU jump to what's currently in the link register, which can be
anything. There it will do crazy things untill it finally segfaults :)

If in doubt, just 'stepi' the program, watching the assembly be executed.

We use the ppc-sim for testing some algorithms to see if they spit out right
reference values.
At the end of our main routine, we always put a 'while(1);' so it never
returns out of there (because where would it return to?? (unless you are
also simulating an operating system under which your test program is running
:) ).

You could also write something to the simulated serial port to indicate that
your program is finished and then do the while(1).

This is what I know about the simulator. It works pretty good for us.

> I'm confused as to how I build/link a program to run under the
> simulator.  My real goal is to extract from the ppc simulator what I
> need to build a coldfire simulator.

The way you build the powerpc program might be ok. You should check what
linker script is that's used as default.
(do 'ppc-eabi-ld --verbose' to display the default linkerscript)

If in doubt, use one of the linkerscript of the
${PREFIX}/${TARGET}/lib/ldscripts/elf32ppcsim.* files.

I hope this helps you a bit further,
Best regards,
Jan

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

* How to build application to run under the ppc simulator?
@ 2003-04-09  4:40 Peter Barada
  0 siblings, 0 replies; 7+ messages in thread
From: Peter Barada @ 2003-04-09  4:40 UTC (permalink / raw)
  To: gdb; +Cc: Peter.Barada, peter


I'm trying to get a handle on how the ppc simulator runs.

I've built a --target=ppc-eabi toolchain, and I've built a tiny little
test program:

int a,b;
int foo(void)
{
 a = 0x1234
 b = 0x5678;
}

I built it with 'ppc-eabi-gcc -o test -g test.c' and fire up
ppc-eabi-gcc on test, and execute:

tar sim
load
run

and it bombs with:

>Program terminated with signal SIGSEGV, Segmentation fault.
>The program no longer exists.
>[Switching to process 0]
>(gdb) 

I'm confused as to how I build/link a program to run under the
simulator.  My real goal is to extract from the ppc simulator what I
need to build a coldfire simulator.

Any comments/ideas are *most* appreciated

-- 
Peter Barada
peter@baradas.org

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

end of thread, other threads:[~2003-04-10  7:12 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-04-10  7:12 How to build application to run under the ppc simulator? Vermeulen Jan
  -- strict thread matches above, loose matches on Subject: below --
2003-04-10  6:02 Vermeulen Jan
2003-04-10  6:08 ` Peter Barada
2003-04-09  6:33 Vermeulen Jan
2003-04-09  6:21 Vermeulen Jan
2003-04-09 16:14 ` Peter Barada
2003-04-09  4:40 Peter Barada

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