<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html;
charset=ISO-8859-1">
</head>
<body text="#000000" bgcolor="#ffffff">
Hi all,<br>
<br>
I am processing DWARF line and column information in (x86 and ARM)
executables in order to produce a mapping from the machine
instructions back to the original source code (C/C++). Using the
line numbers is quite straightforward ("libdwarf" [1] is doing the
work me.) But when comparing the column numbers (extracted from the
DWARF line table) with the corresponding source code locations, it
becomes clear that they are not very "useful".<br>
<br>
Consider the following small example (C++):<br>
<blockquote><tt> 1: #include <iostream><br>
2: #include <ctime><br>
3: #include <cstdlib><br>
4: using namespace std;<br>
5: int main() {<br>
6: int j = 0; cin >> j; long sum = (j < 0 ? -5 : 4)
+ rand();<br>
7: for(int i = 0; i < j; i++) { sum += j*j-2; cout
<< (sum / 2) << endl; }<br>
8: srand(time(NULL));<br>
9: double d = rand() / 10.341; int t = (int)d+j*sum;<br>
10: cout << sum << d << t << j;<br>
11: return (0);<br>
12: }</tt><br>
</blockquote>
Compiling this with "clang++ Main.cpp -g -O3 -o column" result in
the following location information within the generated executable:<br>
<blockquote><tt>$ dwarfdump -l column<br>
<br>
.debug_line: line number info for a single cu<br>
Source lines (from CU-DIE at .debug_info offset 11):<br>
<source file> [line,column] <pc>
//<new stmt or basic block<br>
.../locale_facets.h: [868, 2] 0x80488f0 // new statement</tt><br>
<tt> [...]</tt><br>
<tt>.../Main.cpp: </tt><tt> </tt><tt> [ 8, 2]
0x804896f // new statement</tt><br>
<tt>.../Main.cpp: </tt><tt> </tt><tt> [ 9,28]
0x8048983 // new statement</tt><br>
<tt>.../ostream: </tt><tt> </tt><tt> [165, 9]
0x8048990 // new statement</tt><br>
<tt>.../Main.cpp: </tt><tt> </tt><tt> [ 9,28] 0x80489a0
// new statement</tt><br>
<tt>.../ostream: </tt><tt> </tt><tt> [209, 9]
0x80489ac // new statement</tt><br>
<tt>.../Main.cpp: </tt><tt> </tt><tt> [ 9,28]
0x80489b5 // new statement</tt><br>
<tt>.../ostream: </tt><tt> </tt><tt> [209, 9]
0x80489bb // new statement</tt><br>
<tt> [...]</tt><br>
<tt>.../basic_ios.h: [ 48, 2] 0x8048a23 // new statement
// end of text sequence</tt><br>
</blockquote>
Now, have a look at source code line 9. The extracted debug info
above says that we've 3 "instruction sets" (beginning at <tt>0x8048983,
</tt><tt>0x80489a0</tt> and <tt>0x80489b5</tt> respectively) which
correspond to line 9. But all of them are labeled with column number
28! According to my understanding, this does not contribute any
further information to support my task (= mapping assembler code
back to the source lines or even to statements within a line). Did i
miss anything?<br>
<br>
Furthermore, I would like to use clang as a cross-compiler for ARM
(as mentioned above). Is there any "native" or "default" way to
achieve that? I have already successfully cross-compiled for ARM
using arm-elf-gcc/g++ and newlib. But, for example, compiling with<br>
<blockquote><tt>clang++ -march=armv7-a -mfloat-abi=soft
-ccc-host-triple arm-elf -integrated-as -g Main.cpp -o a.out</tt><br>
</blockquote>
results in the following error message:<br>
<blockquote><tt>Main.cpp:1:10: fatal error: 'iostream' file not
found</tt><br>
<tt>#include <iostream></tt><br>
<tt> ^</tt><br>
<tt>1 error generated.</tt><br>
</blockquote>
Obviously, clang++ cannot find the C++ standard header "iostream".
As far as I know, I have to tell clang++ to use the newlib headers
and libs but I don't know how to do that...<br>
<br>
I would be grateful for any help/hints!<br>
<br>
Best regards<br>
Adrian<br>
<br>
PS: I am using LLVM/clang 3.0, SVN rev. 131589.<br>
<br>
[1] <a
href="http://wiki.dwarfstd.org/index.php?title=Libdwarf_And_Dwarfdump">http://wiki.dwarfstd.org/index.php?title=Libdwarf_And_Dwarfdump</a><br>
<br>
</body>
</html>