Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
CertiCompil
CompCert-KVX
Commits
e2a117e9
Commit
e2a117e9
authored
Jul 03, 2015
by
Bernhard Schommer
Browse files
Allow forward declarations of structure and union types in the debug information.
parent
350354cb
Changes
3
Hide whitespace changes
Inline
Side-by-side
debug/CtoDwarf.ml
View file @
e2a117e9
...
...
@@ -18,6 +18,7 @@ open C2C
open
DwarfTypes
open
DwarfUtil
open
Env
open
Set
(* Functions to translate a C Ast into Dwarf 2 debugging information *)
...
...
@@ -31,6 +32,14 @@ let typedef_table: (string, int) Hashtbl.t = Hashtbl.create 7
(* Hashtable from composite table to entry id *)
let
composite_types_table
:
(
int
,
int
)
Hashtbl
.
t
=
Hashtbl
.
create
7
(* Hashtable from id of a defined composite types to minimal type info *)
let
composite_declarations
:
(
int
,
(
struct_or_union
*
string
*
location
))
Hashtbl
.
t
=
Hashtbl
.
create
7
module
IntSet
=
Set
.
Make
(
struct
type
t
=
int
let
compare
=
compare
end
)
(* Set of all declared composite_types *)
let
composite_defined
:
IntSet
.
t
ref
=
ref
IntSet
.
empty
(* Get the type id of a composite_type *)
let
get_composite_type
(
name
:
int
)
:
int
=
try
...
...
@@ -395,7 +404,7 @@ let struct_to_dwarf (n,at,m) env gloc =
member_bit_size
=
Some
n
;
member_data_member_location
=
None
;
member_declaration
=
None
;
member_name
=
m
.
fld_name
;
member_name
=
if
m
.
fld_name
<>
""
then
Some
m
.
fld_name
else
None
;
member_type
=
t
;
}
in
pack
((
new_entry
(
DW_TAG_member
um
))
::
acc
)
(
e
@
bcc
)
(
l
+
n
)
ms
)
...
...
@@ -413,7 +422,7 @@ let struct_to_dwarf (n,at,m) env gloc =
member_bit_size
=
None
;
member_data_member_location
=
None
;
member_declaration
=
None
;
member_name
=
m
.
fld_name
;
member_name
=
if
m
.
fld_name
<>
""
then
Some
m
.
fld_name
else
None
;
member_type
=
t
;
}
in
translate
((
new_entry
(
DW_TAG_member
um
))
::
acc
)
(
e
@
bcc
)
ms
...
...
@@ -448,7 +457,7 @@ let union_to_dwarf (n,at,m) env gloc =
member_bit_size
=
None
;
member_data_member_location
=
None
;
member_declaration
=
None
;
member_name
=
f
.
fld_name
;
member_name
=
if
f
.
fld_name
<>
""
then
Some
f
.
fld_name
else
None
;
member_type
=
t
;
}
in
new_entry
(
DW_TAG_member
um
)
,
e
@
acc
)[]
m
in
...
...
@@ -468,15 +477,42 @@ let globdecl_to_dwarf env (typs,decls) decl =
typs
@
t
,
d
::
decls
|
Gfundef
f
->
let
t
,
d
=
fundef_to_dwarf
f
decl
.
gloc
in
typs
@
t
,
d
::
decls
|
Genumdef
(
n
,
at
,
e
)
->
let
ret
=
enum_to_dwarf
(
n
,
at
,
e
)
decl
.
gloc
in
typs
@
ret
,
decls
|
Gcompositedef
(
Struct
,
n
,
at
,
m
)
->
let
ret
=
struct_to_dwarf
(
n
,
at
,
m
)
env
decl
.
gloc
in
typs
@
ret
,
decls
|
Gcompositedef
(
Union
,
n
,
at
,
m
)
->
let
ret
=
union_to_dwarf
(
n
,
at
,
m
)
env
decl
.
gloc
in
typs
@
ret
,
decls
|
Gcompositedecl
_
|
Genumdef
(
n
,
at
,
e
)
->
composite_defined
:=
IntSet
.
add
n
.
stamp
!
composite_defined
;
let
ret
=
enum_to_dwarf
(
n
,
at
,
e
)
decl
.
gloc
in
typs
@
ret
,
decls
|
Gcompositedef
(
Struct
,
n
,
at
,
m
)
->
composite_defined
:=
IntSet
.
add
n
.
stamp
!
composite_defined
;
let
ret
=
struct_to_dwarf
(
n
,
at
,
m
)
env
decl
.
gloc
in
typs
@
ret
,
decls
|
Gcompositedef
(
Union
,
n
,
at
,
m
)
->
composite_defined
:=
IntSet
.
add
n
.
stamp
!
composite_defined
;
let
ret
=
union_to_dwarf
(
n
,
at
,
m
)
env
decl
.
gloc
in
typs
@
ret
,
decls
|
Gcompositedecl
(
sou
,
i
,_
)
->
Hashtbl
.
add
composite_declarations
i
.
stamp
(
sou
,
i
.
name
,
decl
.
gloc
);
typs
,
decls
|
Gpragma
_
->
typs
,
decls
let
forward_declaration_to_dwarf
sou
name
loc
stamp
=
let
id
=
get_composite_type
stamp
in
let
tag
=
match
sou
with
|
Struct
->
DW_TAG_structure_type
{
structure_file_loc
=
Some
loc
;
structure_byte_size
=
None
;
structure_declaration
=
Some
true
;
structure_name
=
if
name
<>
""
then
Some
name
else
None
;
}
|
Union
->
DW_TAG_union_type
{
union_file_loc
=
Some
loc
;
union_byte_size
=
None
;
union_declaration
=
Some
true
;
union_name
=
if
name
<>
""
then
Some
name
else
None
;
}
in
{
tag
=
tag
;
children
=
[]
;
id
=
id
}
(* Compute the dwarf representations of global declarations. The second program argument is the
program after the bitfield and packed struct transformation *)
let
program_to_dwarf
prog
prog1
name
=
...
...
@@ -489,7 +525,9 @@ let program_to_dwarf prog prog1 name =
let
typs
=
List
.
map
(
typedef_to_dwarf
None
)
C2C
.
builtins
.
typedefs
in
let
typs
=
List
.
concat
typs
in
let
typs
,
defs
=
List
.
fold_left
(
globdecl_to_dwarf
env
)
(
typs
,
[]
)
prog
in
let
defs
=
typs
@
defs
in
let
typs
=
Hashtbl
.
fold
(
fun
i
(
sou
,
name
,
loc
)
typs
->
if
not
(
IntSet
.
mem
i
!
composite_defined
)
then
(
forward_declaration_to_dwarf
sou
name
loc
i
)
::
typs
else
typs
)
composite_declarations
typs
in
let
defs
=
typs
@
defs
in
let
cp
=
{
compile_unit_name
=
name
;
}
in
...
...
debug/DwarfPrinter.ml
View file @
e2a117e9
...
...
@@ -151,7 +151,7 @@ module DwarfPrinter(Target: DWARF_TARGET)(DwarfAbbrevs:DWARF_ABBREVS):
|
Some
(
DataLocBlock
__
)
->
add_abbr_entry
(
0x38
,
data_location_block_type_abbr
)
buf
|
Some
(
DataLocRef
_
)
->
add_abbr_entry
(
0x38
,
data_location_ref_type_abbr
)
buf
);
add_attr_some
e
.
member_declaration
add_declaration
;
add_name
buf
;
add_
attr_some
e
.
member_name
add_
name
;
add_type
buf
|
DW_TAG_pointer_type
_
->
prologue
0xf
;
...
...
@@ -380,7 +380,7 @@ module DwarfPrinter(Target: DWARF_TARGET)(DwarfAbbrevs:DWARF_ABBREVS):
print_opt_value
oc
mb
.
member_bit_size
print_byte
;
print_opt_value
oc
mb
.
member_data_member_location
print_data_location
;
print_opt_value
oc
mb
.
member_declaration
print_flag
;
print_
string
oc
mb
.
member_name
;
print_
opt_value
oc
mb
.
member_name
print_string
;
print_ref
oc
mb
.
member_type
let
print_pointer
oc
pt
=
...
...
debug/DwarfTypes.mli
View file @
e2a117e9
...
...
@@ -121,7 +121,7 @@ type dw_tag_member =
member_bit_size
:
constant
option
;
member_data_member_location
:
data_location_value
option
;
member_declaration
:
flag
option
;
member_name
:
string
;
member_name
:
string
option
;
member_type
:
reference
;
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment