source line mapping in .s

Hi,

I use CC compiler on Solaris. -S option to earlier version of CC used to provide a mapping between the C/C++ source line number and the equivalent assembly code. But the version of CC available with me doesn't provide source line number in .s anymore. I need this mapping to be able to identify the line number causing exception from the offset available in pstack. Could anyone please tell me how can I get this mapping in .s ? Is there any other option ?

Regards,

Sachin

[502 byte] By [_s_r_s_a] at [2007-11-26 12:34:07]
# 1
This compiler does emit line numbers in assembler files: CC: Sun C++ 5.8 2005/10/13Which one do you have?
MaximKartasheva at 2007-7-7 15:49:15 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 2
Mine is ver 6.000.Is there any way of getting the source line numbers ?
_s_r_s_a at 2007-7-7 15:49:15 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 3
Wow! Latest version is 5.9, at least to my knowledge...
MaximKartasheva at 2007-7-7 15:49:15 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 4
There is no Sun C++ version 6.0. Please run the commandCC -Vand report what it says.
clamage45a at 2007-7-7 15:49:15 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 5
Sorry got it wrong. It is actually 5.3:Sun WorkShop 6 update 2 C++ 5.3 2001/05/15Is there a way to get source line numbers ?
_s_r_s_a at 2007-7-7 15:49:15 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 6

I see no problems with 5.3 either:

$ CC -S a.c

$ cat a.s

<skip>

/ File a.c:

/ Line 8

/ Line 9

pushl$300

callmalloc

addl$4,%esp

movl%eax, -8(%ebp)

/ Line 10

movl$0, -4(%ebp)

jmp.L3

.align 4

<skip>

MaximKartasheva at 2007-7-7 15:49:15 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 7

With 5.3 I get source line, source line number and the corresponding assembly instructions. What I don't get is the hex offset of those assembly instructions which can help me trace the exact source line number of the line causing exception from the pstack of the core. I understand there are other ways of doing that but that can be time consuming in case the file is huge.

_s_r_s_a at 2007-7-7 15:49:15 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 8
I believe missing hex offsets is intentional -- the .s file contains assembler *source* code, which operates in terms of labels, not addresses.
MaximKartasheva at 2007-7-7 15:49:15 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 9
Can you explain why dbx isn't good enough for figuring outwhat source line is causing your exception? If dbx is broken insome way, or doesn't work for your special problem we'd like to know more.--chris
ChrisQuenellea at 2007-7-7 15:49:15 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 10

The process in question cannot be run/debugged in a stand-alone mode. It works as a part of a certain system and gets its input from a few other processes that run along with it. We don't always have access to the lab where this system runs and we don't have a simulator for the same. Sometimes all we have is a corefile and the pstack.

_s_r_s_a at 2007-7-7 15:49:15 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 11
You know, you can pick up a core by dbx...
SFVa at 2007-7-7 15:49:15 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 12
I cannot run my program in a stand-alone mode.
_s_r_s_a at 2007-7-7 15:49:15 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 13

Well, if you can use pstack in order to examine live process (core file) stack, you can use dbx as well. Dbx would allow you to list assembler code (assuming your app is not compiled with -g) and then you can map this piece of assembler to the source by examining .s file generated by the compiler.

MaximKartasheva at 2007-7-7 15:49:15 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 14

I can easily get a pstack from the corefile, but I cannot execute the program/core in dbx because the program during initialization checks for a certain environment, connects to a few other processes which are available only on the target environment and not on my development/test environment.

_s_r_s_a at 2007-7-7 15:49:15 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 15

I didnt say anything about "executing".

You dont have to actually RUN your program if you have core file already.

Please, figure out that *whatever* you can do with pstack you can do the same with dbx (view dead core or attach to a live process). You just plain get more information out of it.

regards,

__Fedor.

SFVa at 2007-7-21 15:38:34 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 16

I sometimes run into a similar situation where I have DTrace-generated

stack traces which provide symbol+offset address that I'd like to map to

high level source lines.

I could probably re-run under dbx to the same point that triggered the

DTrace probe, but it wouldn't always be trivial. [If it were trivial,

I wouldn't have needed to use DTrace to track it down :-) ]

I'd *like* to be able to use some hypothetical dbx command like:

(dbx) lineinfo beta+0x344

==> beta(), line 541 in "supportutils.c"

I used to use the "list -i" command:

(dbx) list -i beta

... source + disassembly listing ...

and manually find the symbol+offset that I'm interested in. Now I use a

"hack" which I have encapsulated into a script which runs the executable

up to "_start" (just to load the shared objects without running any of the

logic of the program), then set the PC to the address in question and

issue a "where" or "list" command:

(dbx) stop in _start

(dbx) run

(dbx) assign $pc=beta+0x344

(dbx) where

=>[1] beta(sz = 0), line 541 in "supportutils.c"

This occasionally works, but usually I have to execute a single "stepi"

command before the high level line number is available. I'm not sure why

that "stepi" is needed.

(dbx) stepi

(dbx) where

=>[1] beta(sz = 0), line 541 in "supportutils.c"

I cringe at executing some arbitrary instruction from the target function

using the "_start" stack frame, but this hack generally seems to do what I

want.

I suspect I've built a Rube Goldberg solution to a simple problem, so I'd

like to ask if there's a simple/robust way to do this mapping within dbx.

-morgan

morganherringtona at 2007-7-21 15:38:34 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 17
For the record, I added some comments to your blog entry on this topic. http://blogs.sun.com/morganh/entry/decoding_symbol_offset_addressesYou can look at the dbx command "where -a 0xNNN" and you couldlook at the GNU utility addr2line.
ChrisQuenellea at 2007-7-21 15:38:34 > top of Java-index,Development Tools,Solaris and Linux Development Tools...