Skip to content

Commit ce4de96

Browse files
author
grischka
committed
tccpe: add COFF symbol table for GDB
wanted by gdb to have global variables info on windows Also: tcc.h: - move dwarf inline fns - use dwarf as default for 64-bit platforms. GDB can't handle locals info from stabs on 64-bit correctly (also not from gcc). tccpe.c: - use 's1' instead of 'pe->s1' tccdbg.c: - fix locals info problem on Windows where (unsigned long) s->value is uint32_t and would not cast to long long correctly. - tweak dwarf to have line info at begin of functions, otherwise "gdb b main, r, n" would say "no line number info, single step..." (see also objdump --dwarf=decodedline ...)
1 parent 03072a3 commit ce4de96

File tree

4 files changed

+183
-132
lines changed

4 files changed

+183
-132
lines changed

configure

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,8 @@ Advanced options (experts only):
234234
Cross build options (experimental):
235235
--cpu=CPU target CPU [$cpu]
236236
--targetos=... target OS (Darwin,WIN32,Android/Termux) [$targetos]
237+
--os-release=x.y.z target os release x.y.z [$os_release] (with BSD systems)
237238
--cross-prefix=PREFIX use PREFIX for compile tools [$cross_prefix]
238-
--os-release=x.y.z use os release x.y.z [$os_release]
239239
EOF
240240
exit 1
241241
}
@@ -260,6 +260,7 @@ fi
260260
# OS specific
261261
buildos=$(uname)
262262
cpu_sys=$(uname -m)
263+
default os_release "$(uname -r)"
263264

264265
case $buildos in
265266
Windows_NT|MINGW*|MSYS*|CYGWIN*)
@@ -294,11 +295,6 @@ then
294295
ar="${cross_prefix}${ar}"
295296
fi
296297

297-
if test -z "$os_release"
298-
then
299-
os_release=$(uname -r)
300-
fi
301-
302298
case "$cpu" in
303299
x86|i386|i486|i586|i686|i86pc|BePC|i686-AT386)
304300
cpu="i386"

tcc.h

Lines changed: 44 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1656,54 +1656,6 @@ static inline void write64le(unsigned char *p, uint64_t x) {
16561656
static inline void add64le(unsigned char *p, int64_t x) {
16571657
write64le(p, read64le(p) + x);
16581658
}
1659-
#define DWARF_MAX_128 ((8 * sizeof (int64_t) + 6) / 7)
1660-
#define dwarf_read_1(ln,end) \
1661-
((ln) < (end) ? *(ln)++ : 0)
1662-
#define dwarf_read_2(ln,end) \
1663-
((ln) + 1 < (end) ? (ln) += 2, read16le((ln) - 2) : 0)
1664-
#define dwarf_read_4(ln,end) \
1665-
((ln) + 3 < (end) ? (ln) += 4, read32le((ln) - 4) : 0)
1666-
#define dwarf_read_8(ln,end) \
1667-
((ln) + 7 < (end) ? (ln) += 8, read64le((ln) - 8) : 0)
1668-
static inline uint64_t
1669-
dwarf_read_uleb128(unsigned char **ln, unsigned char *end)
1670-
{
1671-
unsigned char *cp = *ln;
1672-
uint64_t retval = 0;
1673-
int i;
1674-
1675-
for (i = 0; i < DWARF_MAX_128; i++) {
1676-
uint64_t byte = dwarf_read_1(cp, end);
1677-
1678-
retval |= (byte & 0x7f) << (i * 7);
1679-
if ((byte & 0x80) == 0)
1680-
break;
1681-
}
1682-
*ln = cp;
1683-
return retval;
1684-
}
1685-
static inline int64_t
1686-
dwarf_read_sleb128(unsigned char **ln, unsigned char *end)
1687-
{
1688-
unsigned char *cp = *ln;
1689-
int64_t retval = 0;
1690-
int i;
1691-
1692-
for (i = 0; i < DWARF_MAX_128; i++) {
1693-
uint64_t byte = dwarf_read_1(cp, end);
1694-
1695-
retval |= (byte & 0x7f) << (i * 7);
1696-
if ((byte & 0x80) == 0) {
1697-
if ((byte & 0x40) && (i + 1) * 7 < 64)
1698-
retval |= (uint64_t)-1LL << ((i + 1) * 7);
1699-
break;
1700-
}
1701-
}
1702-
*ln = cp;
1703-
return retval;
1704-
}
1705-
1706-
17071659
/* ------------ i386-gen.c ------------ */
17081660
#if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64 || defined TCC_TARGET_ARM
17091661
ST_FUNC void g(int c);
@@ -1892,6 +1844,49 @@ ST_FUNC void tcc_tcov_reset_ind(TCCState *s1);
18921844
#define dwarf_str_section s1->dwarf_str_section
18931845
#define dwarf_line_str_section s1->dwarf_line_str_section
18941846

1847+
#define DWARF_MAX_128 ((8 * sizeof (int64_t) + 6) / 7)
1848+
#define dwarf_read_1(ln,end) \
1849+
((ln) < (end) ? *(ln)++ : 0)
1850+
#define dwarf_read_2(ln,end) \
1851+
((ln) + 1 < (end) ? read16le(((ln)+=2) - 2) : 0)
1852+
#define dwarf_read_4(ln,end) \
1853+
((ln) + 3 < (end) ? read32le(((ln)+=4) - 4) : 0)
1854+
#define dwarf_read_8(ln,end) \
1855+
((ln) + 7 < (end) ? read64le(((ln)+=8) - 8) : 0)
1856+
static inline uint64_t
1857+
dwarf_read_uleb128(unsigned char **ln, unsigned char *end)
1858+
{
1859+
unsigned char *cp = *ln;
1860+
uint64_t retval = 0;
1861+
int i;
1862+
for (i = 0; i < DWARF_MAX_128; i++) {
1863+
uint64_t byte = dwarf_read_1(cp, end);
1864+
retval |= (byte & 0x7f) << (i * 7);
1865+
if ((byte & 0x80) == 0)
1866+
break;
1867+
}
1868+
*ln = cp;
1869+
return retval;
1870+
}
1871+
static inline int64_t
1872+
dwarf_read_sleb128(unsigned char **ln, unsigned char *end)
1873+
{
1874+
unsigned char *cp = *ln;
1875+
int64_t retval = 0;
1876+
int i;
1877+
for (i = 0; i < DWARF_MAX_128; i++) {
1878+
uint64_t byte = dwarf_read_1(cp, end);
1879+
retval |= (byte & 0x7f) << (i * 7);
1880+
if ((byte & 0x80) == 0) {
1881+
if ((byte & 0x40) && (i + 1) * 7 < 64)
1882+
retval |= (uint64_t)-1LL << ((i + 1) * 7);
1883+
break;
1884+
}
1885+
}
1886+
*ln = cp;
1887+
return retval;
1888+
}
1889+
18951890
/* default dwarf version for "-gdwarf" */
18961891
#ifdef TCC_TARGET_MACHO
18971892
# define DEFAULT_DWARF_VERSION 2
@@ -1904,9 +1899,7 @@ ST_FUNC void tcc_tcov_reset_ind(TCCState *s1);
19041899
# define CONFIG_DWARF_VERSION 0
19051900
#endif
19061901

1907-
#if defined TCC_TARGET_PE
1908-
# define R_DATA_32DW 'Z' /* fake code to avoid DLL relocs */
1909-
#elif defined TCC_TARGET_X86_64
1902+
#if defined TCC_TARGET_X86_64
19101903
# define R_DATA_32DW R_X86_64_32
19111904
#else
19121905
# define R_DATA_32DW R_DATA_32

tccdbg.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1500,6 +1500,8 @@ ST_FUNC void tcc_debug_line(TCCState *s1)
15001500
else {
15011501
dwarf_line_op(s1, DW_LNS_advance_line);
15021502
dwarf_sleb128_op(s1, len_line);
1503+
/* advance by nothing */
1504+
dwarf_line_op(s1, DWARF_OPCODE_BASE - DWARF_LINE_BASE);
15031505
}
15041506
}
15051507
}
@@ -2209,9 +2211,9 @@ static void tcc_debug_finish (TCCState *s1, struct _debug_info *cur)
22092211
}
22102212
else {
22112213
/* param/local */
2212-
dwarf_data1(dwarf_info_section, dwarf_sleb128_size(s->value) + 1);
2214+
dwarf_data1(dwarf_info_section, dwarf_sleb128_size((long)s->value) + 1);
22132215
dwarf_data1(dwarf_info_section, DW_OP_fbreg);
2214-
dwarf_sleb128(dwarf_info_section, s->value);
2216+
dwarf_sleb128(dwarf_info_section, (long)s->value);
22152217
}
22162218
tcc_free (s->str);
22172219
}

0 commit comments

Comments
 (0)