The assembler listing and the map files are essential tools for debugging using the kernel debugger. In order to create the assembler list file during compilation, use the -qlist option while compiling. Also use the -qsource option to get the C source listing in the same file:
cc -c -DEBUG -D_KERNEL -DIBMR2 demodd.c -qsource -qlist
In order to obtain the map file, use the -bmap:FileName option on the link editor, enter:
ld -o demodd demodd.o -edemoconfig -bimport:/lib/kernex.exp \ -lsys -lcsys -bmap:demodd.map -bE:demodd.exp
You can also create a map file with a slightly different format by using the nm command. For example, use the following command to get a map listing for the kernel (/unix):
nm -xv /unix > unix.m
The assembler and source listing is used to correlate any C source line with the corresponding assembler lines. The following is a portion of the C source code for a sample device driver. The left column is the line number in the source code:
. . 185 186 if (result = devswadd(devno, &demo_dsw)){ 187 printf("democonfig : failed to add entry points\n"); 188 (void)devswdel(devno); 189 break; 190 } 191 dp->inited = 1; 192 demos_inited++; 193 printf("democonfig : CFG_INIT success\n"); 194 break; 195 . .
The following is a portion of the assembler listing for the corresponding C code shown previously. The left column is the C source line for the corresponding assembler statement. Each C source line can have multiple assembler source lines. The second column is the offset of the assembler instruction with respect to the kernel extension entry point.
. . 186| 000218 l 80610098 2 L4Z gr3=devno(gr1,152) 186| 00021C cal 389F0000 1 LR gr4=gr31 186| 000220 bl 4BFFFDE1 0 CALL gr3=devswadd,2, gr3,(struct_4198576)",gr4,devswadd",gr1,cr[01567],gr0", gr4"-gr12",fp0"-fp13" 186| 000224 cror 4DEF7B82 1 186| 000228 st 9061005C 2 ST4A #2357(gr1,92)=gr3 186| 00022C st 9061003C 1 ST4A result(gr1,60)=gr3 186| 000230 l 8061005C 1 L4A gr3=#2357(gr1,92) 186| 000234 cmpi 2C830000 2 C4 cr1=gr3,0 186| 000238 bc 41860020 3 BT CL.16,cr1,0x4/eq 187| 00023C ai 307F01A4 1 AI gr3=gr31,420 187| 000240 bl 4BFFFDC1 2 CALL gr3=printf,1,'democonfig : failed to add entry points",gr3,printf",gr1,cr[01567],gr0", gr4"-gr12",fp0"-fp13" 187| 000244 cror 4DEF7B82 1 188| 000248 l 80610098 2 L4Z gr3=devno(gr1,152) 188| 00024C bl 4BFFFDB5 0 CALL gr3=devswdel,1,gr3, devswdel",gr1,cr[01567],gr0",gr4"-gr12",fp0"-fp13" 188| 000250 cror 4DEF7B82 1 189| 000254 b 48000104 0 B CL.6 186| CL.16: 191| 000258 l 80810040 2 L4Z gr4=dp(gr1,64) 191| 00025C cal 38600001 1 LI gr3=1 191| 000260 stb 98640004 1 ST1Z (char)(gr4,4)=gr3 192| 000264 l 8082000C 1 L4A gr4=.demos_inited(gr2,0) 192| 000268 l 80640000 2 L4A gr3=demos_inited(gr4,0) 192| 00026C ai 30630001 2 AI gr3=gr3,1 192| 000270 st 90640000 1 ST4A demos_inited(gr4,0)=gr3 193| 000274 ai 307F01D0 1 AI gr3=gr31,464 193| 000278 bl 4BFFFD89 0 CALL gr3=printf,1,'democonfig : CFG_INIT success",gr3,printf",gr1,cr[01567],gr0",gr4"-gr12", fp0"-fp13" 193| 00027C cror 4DEF7B82 1 194| 000280 b 480000D8 0 B CL.6 . .
Now with both the assembler listing and the C source listing, you can determine the assembler instruction for a C statement. As an example, consider the C source line at line 191 in the sample code:
191 dp->inited = 1;
The corresponding assembler instructions are:
191| 000258 l 80810040 2 L4Z gr4=dp(gr1,64) 191| 00025C cal 38600001 1 LI gr3=1 191| 000260 stb 98640004 1 ST1Z (char)(gr4,4)=gr3
The offsets of these instructions within the sample device driver (demodd) are 000258, 00025C, and 000260.
The binder map file is a symbol map in address order format. Each symbol listed in the map file has a storage class (CL ) and a type (TY ) associated with it.
Storage classes correspond to the XMC_XX variables defined in the syms.h file. Each storage class belongs to one of the following section types:
Types correspond to the XTY_XX variables defined in the syms.h file. The type (TY ) can be one of the following values:
ER | External Reference |
LD | Label Definition |
SD | Section Definition |
CM | BSS Common Definition |
The following is a map file for a sample device driver:
1 ADDRESS MAP FOR demodd 2 SOURCE-FILE(OBJECT) or *IE ADDRESS LENGTH AL CL TY Sym# NAME IMPORT-FILE{SHARED-OBJECT} 3 --- -------- ------ -- -- -- ---- ---------- -------------------------- 4 I ER S1 pinned_heap /lib/kernex.exp{/unix} 5 I ER S2 devswadd /lib/kernex.exp{/unix} 6 I ER S3 devswdel /lib/kernex.exp{/unix} 7 I ER S4 nodev /lib/kernex.exp{/unix} 8 I ER S5 printf /lib/kernex.exp{/unix} 9 I ER S6 uiomove /lib/kernex.exp{/unix} 10 I ER S7 xmalloc /lib/kernex.exp{/unix} 11 I ER S8 xmfree /lib/kernex.exp{/unix} 12 00000000 0008B8 2 PR SD S9 <> /tmp/cliff/demodd/demodd.c(demodd.o) 13 00000000 PR LD S10 .democonfig 14 0000039C PR LD S11 .demoopen 15 000004B4 PR LD S12 .democlose 16 000005D4 PR LD S13 .demoread 17 00000704 PR LD S14 .demowrite 18 00000830 PR LD S15 .get_dp 19 000008B8 000024 2 GL SD S16 <.printf> glink.s(/usr/lib/glink.o) 20 000008B8 GL LD S17 .printf 21 000008DC 000024 2 GL SD S18 <.xmalloc> glink.s(/usr/lib/glink.o) 22 000008DC GL LD S19 .xmalloc 23 00000900 000090 2 PR SD S20 .bzero noname(/usr/lib/libcsys.a[bzero.o]) 24 00000990 000024 2 GL SD S21 <.uiomove> glink.s(/usr/lib/glink.o) 25 00000990 GL LD S22 .uiomove 26 000009B4 000024 2 GL SD S23 <.devswadd> glink.s(/usr/lib/glink.o) 27 000009B4 GL LD S24 .devswadd 28 000009D8 000024 2 GL SD S25 <.devswdel> glink.s(/usr/lib/glink.o) 29 000009D8 GL LD S26 .devswdel 30 000009FC 000024 2 GL SD S27 <.xmfree> glink.s(/usr/lib/glink.o) 31 000009FC GL LD S28 .xmfree 32 00000000 000444 4 RW SD S29 <_/tmp/cliff/demodd/demodd$c$> /tmp/cliff/demodd/demodd.c(demodd.o) 33 00000450 000004 4 RW SD S30 demo_dev /tmp/cliff/demodd/demodd.c(demodd.o) 34 00000460 000004 4 RW SD S31 demos_inited /tmp/cliff/demodd/demodd.c(demodd.o) 35 00000470 000080 4 RW SD S32 data /tmp/cliff/demodd/demodd.c(demodd.o) 36 * E 000004F0 00000C 2 DS SD S33 democonfig /tmp/cliff/demodd/demodd.c(demodd.o) 37 E 000004FC 00000C 2 DS SD S34 demoopen /tmp/cliff/demodd/demodd.c(demodd.o) 38 E 00000508 00000C 2 DS SD S35 democlose /tmp/cliff/demodd/demodd.c(demodd.o) 39 E 00000514 00000C 2 DS SD S36 demoread /tmp/cliff/demodd/demodd.c(demodd.o) 40 E 00000520 00000C 2 DS SD S37 demowrite /tmp/cliff/demodd/demodd.c(demodd.o) 41 0000052C 000000 2 T0 SD S38 <TOC> 42 0000052C 000004 2 TC SD S39 <_/tmp/cliff/demodd/demodd$c$> 43 00000530 000004 2 TC SD S40 <printf> 44 00000534 000004 2 TC SD S41 <demo_dev> 45 00000538 000004 2 TC SD S42 <demos_inited> 46 0000053C 000004 2 TC SD S43 <data> 47 00000540 000004 2 TC SD S44 <pinned_heap> 48 00000544 000004 2 TC SD S45 <xmalloc> 49 00000548 000004 2 TC SD S46 <uiomove> 50 0000054C 000004 2 TC SD S47 <devswadd> 51 00000550 000004 2 TC SD S48 <devswdel> 52 00000554 000004 2 TC SD S49 <xmfree>
In the sample map file listed previously, the .data section starts from the statement at line 32:
32 00000000 000444 4 RW SD S29 <_/tmp/cliff/demodd/demodd$c$> /tmp/cliff/demodd/demodd.c(demodd.o)
The TOC (Table of Contents) starts from the statement at line 41:
41 0000052C 000000 2 T0 SD S38 <TOC>