"dev_list'next", { mandatory_field = false; list_head_adjustment = true };
"next", { mandatory_field = false; list_head_adjustment = true };
"name", ordinary_field;
- "dev_addr", ordinary_field;
+ "flags", ordinary_field;
+ "operstate", ordinary_field;
+ "mtu", ordinary_field;
+ "perm_addr", ordinary_field;
+ "addr_len", ordinary_field;
+ "ip_ptr", ordinary_field;
+ "ip6_ptr", ordinary_field;
]
};
"net", {
{ mandatory_field = true; list_head_adjustment = false };
]
};
+ "in_device", {
+ opener = "struct in_device {"; closer = "};"; mandatory_struct = true;
+ fields = [
+ "ifa_list", ordinary_field;
+ ];
+ };
+ "inet6_dev", {
+ opener = "struct inet6_dev {"; closer = "};"; mandatory_struct = true;
+ fields = [
+ "addr_list", ordinary_field;
+ ];
+ };
+ "in_ifaddr", {
+ opener = "struct in_ifaddr {"; closer = "};"; mandatory_struct = true;
+ fields = [
+ "ifa_next", ordinary_field;
+ "ifa_local", ordinary_field;
+ "ifa_address", ordinary_field;
+ "ifa_mask", ordinary_field;
+ "ifa_broadcast", ordinary_field;
+ ];
+ };
+ "inet6_ifaddr", {
+ opener = "struct inet6_ifaddr {"; closer = "};"; mandatory_struct = true;
+ fields = [
+ (*"addr'in6_u'u6_addr8", ordinary_field;*)
+ "prefix_len", ordinary_field;
+ "lst_next", ordinary_field;
+ ];
+ };
]
let debug = false
* XXX Even better would be to have a proper interface to libdwarves.
*)
let re_offsetsize = Pcre.regexp "/\\*\\s+(\\d+)\\s+(\\d+)\\s+\\*/" in
- let re_intfield = Pcre.regexp "int\\s+(\\w+);" in
+ let re_intfield = Pcre.regexp "(?:int|char)\\s+(\\w+);" in
let re_ptrfield = Pcre.regexp "struct\\s+(\\w+)\\s*\\*\\s*(\\w+);" in
+ let re_voidptrfield = Pcre.regexp "void\\s*\\*\\s*(\\w+);" in
let re_strfield = Pcre.regexp "char\\s+(\\w+)\\[(\\d+)\\];" in
let re_structopener = Pcre.regexp "(struct|union)\\s+.*{$" in
let re_structcloser = Pcre.regexp "}\\s*(\\w+)?(\\[\\d+\\])?;" in
Not_found -> parse basename lines
);
+ | line :: lines when Pcre.pmatch ~rex:re_voidptrfield line ->
+ (* A void* field. *)
+ let subs = Pcre.exec ~rex:re_voidptrfield line in
+ let name = Pcre.get_substring subs 1 in
+ (try
+ let subs = Pcre.exec ~rex:re_offsetsize line in
+ let offset = int_of_string (Pcre.get_substring subs 1) in
+ let size = int_of_string (Pcre.get_substring subs 2) in
+ (name, (`VoidPtr, offset, size))
+ :: parse basename lines
+ with
+ Not_found -> parse basename lines
+ );
+
| line :: lines when Pcre.pmatch ~rex:re_strfield line ->
(* A string (char array) field. *)
let subs = Pcre.exec ~rex:re_strfield line in
(* That got us all the fields, but we only care about
* the wanted_fields.
*)
+ let all_fields = fields in
let fields = List.filter (
fun (name, _) -> List.mem_assoc name wanted_fields
) fields in
(* Also check we have all the mandatory fields. *)
List.iter (
fun (wanted_field, { mandatory_field = mandatory }) ->
- if mandatory && not (List.mem_assoc wanted_field fields) then
- failwith (sprintf "%s: structure %s is missing required field %s" basename struct_name wanted_field)
+ if mandatory && not (List.mem_assoc wanted_field fields)
+ then (
+ eprintf "%s: structure %s is missing required field %s\n" basename struct_name wanted_field;
+ eprintf "fields found in this structure:\n";
+ List.iter (
+ fun (name, _) -> eprintf "\t%s\n" name
+ ) all_fields;
+ exit 1
+ );
) wanted_fields;
(* Prefix all the field names with the structure name. *)
printf " int %s; " field_name
| `Ptr struct_name ->
printf " struct %s *%s; " struct_name field_name
+ | `VoidPtr ->
+ printf " void *%s; " field_name
| `Str width ->
printf " char %s[%d]; " field_name width
);
<:ctyp< $lid:name$ : int64 >>
| (name, (`Int, { mandatory_field = false })) ->
<:ctyp< $lid:name$ : int64 option >>
- | (name, (`Ptr _, { mandatory_field = true })) ->
+ | (name, ((`VoidPtr|`Ptr _), { mandatory_field = true })) ->
<:ctyp< $lid:name$ : Virt_mem_mmap.addr >>
- | (name, (`Ptr _, { mandatory_field = false })) ->
+ | (name, ((`VoidPtr|`Ptr _), { mandatory_field = false })) ->
<:ctyp< $lid:name$ : Virt_mem_mmap.addr option >>
| (name, (`Str _, { mandatory_field = true })) ->
<:ctyp< $lid:name$ : string >>
String.concat ";\n " (
List.map (
function
- | (field_name, (`Int, offset, size))
- | (field_name, (`Ptr _, offset, size)) ->
+ | (field_name, ((`Int|`Ptr _|`VoidPtr), offset, size)) ->
(* 'zero+' is a hack to force the type to int64. *)
sprintf "%s : zero+%d : offset(%d), %s"
field_name (size*8) (offset*8) endian