# CDB File format Description

The .cdb file created when the --debug option is used contains the following types of records. The records are stored one per line, and the first character determines the record type.

#### Type Description Generated by

- 'S' Symbol Record Compiler
- 'T' Structure description record Compiler
- 'L' Linker record assembler/linker
- 'F' Function record Compiler
- 'M' Module record Compiler

#### Details of 'S'-Type (Symbol Record)

A symbol record is generated for each named symbol in the source file (local, global & parameter). The format of the symbol record is as follows.

S:{G|F<filename>|L<functionName>}$<name>$<level>$<block> (<type info>),<Address Space>,<on Stack?>,<stack offset>

Following the record type is the scope information for the symbol. 'G' indicates Global . F<filename> indicates the symbol is active for a given file only (e.g. global variables declared as 'static') L<functionName> indicates that the symbol is local to the function with the given name. The follows the name of the variable (this is the unmangled/user given name of the variable). The level & block are used to further scope local variables since C allows the definitions like ...

foo()
{
int c; /* block #1 , level #1 */
{
int c; /* block #2, level #2 */
...
}

{
int c; /* block #3 , level #2 */
...
}
}

The type info is a chain of type (since C allows declarations of arbitrary complexity. The type info has the following format .

({size}<type info chain>)

size - size in bytes of the symbol.

<type info chain> - should be parsed into a linked list of type, the elements of the list are described below.

Type Code | Description
DA<n> | Array of n elements
DF | Function
DG | Generic pointer
DC | Code pointer
DX | Xternal Ram pointer
DD | Internal ram pointer
DP | Paged pointer
DI | Upper 128 byte pointer
SL | long
SI | int
SC | char
SS | short
SV | void
SF | float
ST<name> | structure of name <name>
SX | sbit
SB<n> | bit field of <n> bits.

Address Space
Code Description
---- -----------

Address Space Code | Description of address space
A | External stack
B | Internal stack
C | Code
D | Code/static segment
E | Internal ram (lower 128) bytes
F | External ram
G | Internal ram
H | Bit addressable
I | SFR space
J | SBIT space

Sign Information
Code Description
---- -----------
S Signed
U Unsigned

Examples
--------
This is best illustrated with a few examples.

Declaration.

idata char BCD_Cell[5];

Generates the following debug info.

S:G$BCD_cell$0$0({5}DA5,SC:S),G,0,0

The following function declaration along with local variables and parameters.

void uitoa(unsigned int value, char* string, int radix)
{
char buffer[NUMBER_OF_DIGITS];

..
}

Will generate the following debug information.

/* function "uitoa" */
F:G$uitoa$0$0({2}DF,SV:S),C,0,0

/* parameter "value" */
S:Luitoa$value$1$1({2}SI:S),E,0,0

/* parameter "string" */
S:Luitoa$string$1$1({3}DG,SC:S),E,0,0

/* parameter "radix" */
S:Luitoa$radix$1$1({2}SI:S),E,0,0

/* local variable "buffer" */
S:Luitoa$buffer$1$1({16}DA16,SC:S),E,0,0

Details of 'T'-Type (Structure Record)
--------------------------------------
Structure definitions ALWAYS have file scope. Currently structure definitions
within functions or blocks are not handled in the debug information. Structure
and unions are represented using the same debug format. The format of the
Structure record is as follows .

T:F<filename>$tag[({offset}<Symbol Record 'S' type for 1st field>)
({offset}<Symbol Record 'S' type for 2nd field>)
...
...
]

Example 1.
----------

Definition

struct some_struct {
int a;
char b;
long c;
};

Generates the following 'T' - type record.

T:Fprob38$some_struct[
/* field 'a' offset = 0 */
({0}S:S$a$1$0({2}SI:S),Z,0,0)
/* field 'b' offset = 2 */
({2}S:S$b$1$0({1}SC:S),Z,0,0)
/* field 'c' offset = 3 */
({3}S:S$c$1$0({4}SL:S),Z,0,0)]

The 'S' - type (symbol rescord for each of the fields is embedded inside
the structure definition record.

Example 2.
----------

Structure declarations with embeded structures.

union bil {
struct {
volatile unsigned char b0,
b1,
b2,
b3 ;
} b;
struct {
volatile unsigned int lo,hi ;
} i;
unsigned volatile long l;
struct {
volatile unsigned char b0;
unsigned int i12;
unsigned char b3;}
bi;
} ;

Generates the following debug information. NOTE: the embedded anonymous
structures generates separate T - type records.

T:Fprob38$bil[
/* field 'b' is of type Structure __00020000 , offset = 0 */
({0}S:S$b$1$0({4}ST__00020000:S),Z,0,0)

/* field 'i' is of type structre __00020001 , offset = 0 (union) */
({0}S:S$i$1$0({4}ST__00020001:S),Z,0,0)

/* field 'l' is of type unsigned long */
({0}S:S$l$1$0({4}SL:U),Z,0,0)

/* field 'bi' is of type structure __00020002 offset = 0 */
({0}S:S$bi$1$0({4}ST__00020002:S),Z,0,0)]

/* compiler generates these 'T'-type records for the
anonymous structures */

/* T record for structure __00020000 (field 'b' in the above structure) */

T:Fprob38$__00020000[
/* field 'b0' type unsigned char , offset = 0 */
({0}S:S$b0$2$0({1}SC:U),Z,0,0)

/* field 'b1' type unsigned char , offset = 1 */
({1}S:S$b1$2$0({1}SC:U),Z,0,0)

/* field 'b2' type unsigned char, offset = 2 */
({2}S:S$b2$2$0({1}SC:U),Z,0,0)

/* field 'b3' type unsigned char , offset = 3 */
({3}S:S$b3$2$0({1}SC:U),Z,0,0)]

/* T record for structure __00020001 (field 'i' in union 'bil' ) */

T:Fprob38$__00020001[
/* field 'lo' type unsigned int offset 0 */
({0}S:S$lo$2$0({2}SI:U),Z,0,0)

/* field 'hi' type unsigned int offset 2 */
({2}S:S$hi$2$0({2}SI:U),Z,0,0)]

/* T record for structure __00020002 (field 'bi' in union 'bil' )*/

T:Fprob38$__00020002[
/* field 'b0' type unsigned char , offset 0 */
({0}S:S$b0$2$0({1}SC:U),Z,0,0)

/* field 'i1' type unsigned int , offset 1 */
({1}S:S$i12$2$0({2}SI:U),Z,0,0)

/* field 'b3' type unsigned char offset 3 */
({3}S:S$b3$2$0({1}SC:U),Z,0,0)]

Details of 'F'-Type (FUNCTION Record)
--------------------------------------
A Function record is created for each function defined in the C Source
file. The format of a function record is identical to that of the Symbol
record. The function record contains information about the return value
of a function, in addition it contains information about the register bank
the function uses and if the function is an interrupt service routine the
interrupt number of the function.

Example 1.
----------