Menu ▾ ▴

#4243 z80: --debug writes no S: record for a const global defined before a function

open
nobody
None
Z80
5
2026-11-03
2026-11-03
No

With --debug, the z80 port writes no CDB S: record for a const global that is defined before a function. mcs51 and stm8 write it.

SDCC 4.5.0 #15242 (Linux, Fedora 44 package sdcc-4.5.0-1.fc44). Also seen in z88dk's zsdcc (SDCC 4.6.0 #16639 based).

#include <stdint.h>
const uint8_t ctab[4] = { 1, 2, 3, 4 };
const uint16_t cval = 0x1234;
uint8_t dval = 7;
int main(void) { return ctab[dval & 3] + cval; }

sdcc -mz80 --debug -c u4.c, u4.adb:

S:G$dval$0_0$0({1}SC:U),E,0,0
S:G$main$0_0$0({2}DF,SI:S),C,0,0

sdcc -mmcs51 --debug -c u4.c (and -mstm8) also write:

S:G$ctab$0_0$0({4}DA4d,SC:U),D,0,0
S:G$cval$0_0$0({2}SI:U),D,0,0

The linked .cdb of the z80 build has no record for ctab or cval either, although u4.asm emits G$ctab$0_0$0 == . and G$cval$0_0$0 == ..

The record is written on z80 when the const global comes after the last function, or when the file has no function:

extern const uint8_t late[2];
uint8_t dval = 7;
int main(void) { return late[dval & 1]; }
const uint8_t late[2] = { 1, 2 };          /* S:G$late$0_0$0({2}DA2d,SC:U),D,0,0 is written */

This points at flushStatics(). The z80 code generator calls it after each function, and it emits statsg and then clears it (statsg->syms = 0), before outputDebugSymbols() walks statsg to write the records. With SDCC_DEBUG_VAR_STORAGE=1, mcs51 lists _ctab/_cval under "Statics" and z80 lists them nowhere. A possible fix: have flushStatics() write the debug records of the symbols it drops when --debug is on.

Expected: an S:G record for every global, as on the other ports.

Why it matters: a debugger reading the .cdb cannot show a const table with its type (no array bounds, no element type), only as raw bytes at an address.

Discussion


Log in to post a comment.