Commit Graph

22 Commits

Author SHA1 Message Date
grischka
8c5fe87665 tcc -g1 : small debug info (lines/functions only) 2023-09-06 22:42:47 +02:00
grischka
452045422b win32: pe dwarf sections & option -g.pdb
On windows, create a .pdb file with option "-g.pdb"
Such executables created by tcc can be debugged with
"ollydbg" or "x64dbg"

This currently relies on the 3rd party tool cv2pdb from
    https://github.com/rainers/cv2pdb
which again relies on
    mspdbsrv.exe mspdbcore.dll msobj80.dll mspdb80.dll
from a MSVC installation.

cv2pdb.exe + the ms* files may be put in the path or in the
same directory as tcc.exe.
2023-09-06 22:42:44 +02:00
grischka
40131b7e0f MEM_DEBUG thread-safe & tccdbg leakless
libtcc.c:
- guard tcc_realloc/free_debug() with a semaphore
tccdbg.c:
- allow tcc_debug_end() to be called twice safely
2023-04-25 15:22:15 +02:00
herman ten brugge
2cb8bddd82 Add attribute nodebug support and skip bitfield padding
The following code:
typedef struct {
  unsigned int a __attribute__((nodebug));
  unsigned int b;
  unsigned int : 32;
  unsigned int c;
} tst;

Supresses a and also suppresses bitfield padding.
So debugger shows only b and c in above example.
2023-03-10 12:41:43 +01:00
herman ten brugge
4dc7662a07 Fix preprocessor line directive update
The last commit was not a problem with macos.
The problem was that dwarf version < 5 uses different indexes for
files and directories.
They start at 1 for dwarf version < 5 and 0 for dwarf version >= 5.
2023-01-17 20:08:14 +01:00
herman ten brugge
d0efbc5d3a Fix preprocessor line directive for macos
Macos has an offset of 1 for DW_LNS_set_file.

Also rewrite dwarf_file to not scan list twice and
move check for <command line> to this function.
2023-01-16 20:26:44 +01:00
herman ten brugge
ee3fef2ce2 Fix preprocessor line directive
The preprocessor line directive did not result in correct debug info
when -g was used.
Line directives like:
 #line 1 "filename"
should now work.
2023-01-16 08:39:34 +01:00
herman ten brugge
079692016d Fix stab debug problem with common section 2022-12-11 15:36:37 +01:00
herman ten brugge
7cc1cc3881 Fix for lldb usage
lldb does not like function end and next function start at same pc
2022-12-04 07:19:48 +01:00
herman ten brugge
6b398686d6 Fix bounds checking without -run on macos
Update tccrun.c to detect rebase for dwarf debug info.
Enabled testcase 126 on macos.
Add prologue_end/epilogue_begin supoort in tcc.h, tccdbg.c, tccgen.c.
2022-12-02 13:09:47 +01:00
herman ten brugge
60d52f0d68 Fix add debug support to macos 2022-12-02 07:05:12 +01:00
herman ten brugge
62096265ed Add debug support to macos
lldb now works with this push.

In tccmacho.c add S_ATTR_DEBUG to all debug sections.
Add __DWARF section and rearange struct skinfo.

In tccdbg.c The first filename in dwarf_line can not be used.
Also had to fix structure/union/lexical_block/subroutine to
allow empty childs.
dwarfdump --verify complained about this.
2022-11-30 21:49:07 +01:00
grischka
e41730f11a - tcc -vv: show cross-libtcc1.a correctly (and more)
(As long as it is in the default install location and was not
moved elsewhere into the library search path manually)

Also:
- libtcc.c:
  - error1(): show correct line with "In file included from ..."
  - support "tcc -Bxxx -vv"
  - tcc_new()/tcc_compile(): Don't create elf sections for tcc -E
- tccdbg.c:
  - tcc -E -g : revert 1de025c13a
    Let's keep things simple, everybody understands 'do_debug'
    and dState is set by tcov too (but no debug sections).
- tccgen.c:
  - avoid the extra parameter for gind()
    (from c3e3a07ed4)
  - vla func params: use skip_or_save_block() and enable
    VT_LVAL (see 313855c232)
  - cleanup nocode_wanted a bit
- tccelf.c:
  - tccelf_end_file(): don't try to translate zero-sym relocs
    (seems to happen with asm "jmp 0x1000")
  - version_add(): do not make "ld-linux.so" DT_NEEDED
2022-09-24 09:46:17 +02:00
herman ten brugge
1de025c13a Check dState instead of do_debug in tccdbg.c
This fixes:
  tcc -g -E

and programs like:
  #pragma comment (option,"-g")
  int main(void) {return 0;}
2022-08-11 09:03:13 +02:00
grischka
ebaa5c81f4 dynamic executables (PIE)
Allows to create dynamic executables, using the code path
for TCC_OUTPUT_DLL but add an .interp header (plus a FLAGS_1
entry in the dynamic section to make 'readelf' say "PIE")

Introduces TCC_OUTPUT_DYN as alias for TCC_OUTPUT_DLL.
There is no runtime option,  only one to configure:

    ./configure --config-pie

100 insertions(+), 76 deletions(-)
2022-07-24 09:44:50 +02:00
herman ten brugge
a4e0f7ef05 Fix bitfield long types for stabs/dwarf
Also made dwarf *leb128 fuctions a litlle bit faster.
2022-05-25 17:04:37 +02:00
herman ten brugge
aaec564a82 Fix bound checking dlcose problem
The main problem is that an application called dlclose and then
had a bound checking problem. The list of dll's in tccrun was
not updated an caused a crash.
Also fixed some minor other things.

tccdbg.c:
- Allow filenames like ../file.c
- Rewrite DWARF_ABBREV_MEMBER_BF/DWARF_ABBREV_MEMBER a bit

tccelf.c:
- Add call to __bt_exit. This solves problem when dlclose is called

tccrun.c:
- Rewrite rt_printline_dwarf a litlle to use opcode_length correctly
- Do not stop at DW_LNE_end_sequence
- Fix DW_LNE_set_address again. Works now in *bsd.

lib/bt-exe.c lib/bt-dll.c:
- Add __bt_exit/__bound_exit_dll

lib/bcheck.c:
- Add __bound_exit_dll
2022-05-19 07:40:14 +02:00
herman ten brugge
0e47167cbe New dwarf update
tccdbg.c
- Fix typo in dwarf_file. This resulted in not finding correct include
  files.

tccrun.c:
- Change FILE_TABLE_SIZE to 512. Some files use very large includes.
- When a dll containted more then 1 file the pc was not calculated
  correctly.
2022-05-14 15:58:40 +02:00
herman ten brugge
e7396c99b0 Dwarf update
Some small updates in tccdbg.c found by checking readelf output from
gcc/clang.

- Change encoding type bool type
- Fix enum signed/unsigned
- Do not hash anon symbol
- Use correct filename/line_number for global variables
- Fix compiler warning in tcc_get_dwarf_info
- Use unsigned long long for array indexes
- Display correct first line of function in gdb
2022-05-12 08:15:28 +02:00
herman ten brugge
748e38ad99 Fix stupid typo. 2022-05-10 07:21:49 +02:00
herman ten brugge
9a81e6366b Fix vla type bug for stabs/dwarf
The wrong vla stabs code was accepted by gdb.
The dwarf vla code was fatal.
2022-05-10 07:16:38 +02:00
grischka
2caaff20fb tccdbg.c: new file
Better avoid global variables, at least in new code.

tccdbg.c hopefully should be logically identical to the
former parts in tccgen/elf.c (s1 tccstate added in some
places)

tccelf.c: dwarf linkage seems special per dwarf rather
than special per target.
2022-05-09 22:37:25 +02:00