Separate out the parsing code into a separately defined module. *NOT WORKING*
[virt-mem.git] / extract / codegen / pahole_parser.mli
1 (** 'pahole' output parser. *)
2 (* Memory info command for virtual domains.
3    (C) Copyright 2008 Richard W.M. Jones, Red Hat Inc.
4    http://libvirt.org/
5
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2 of the License, or
9    (at your option) any later version.
10
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  *)
20
21 (** This parses the output of the pahole command, allowing us
22     to extract the layout of kernel structures for particular
23     kernel versions.
24
25     Its primary input is the [*.info] and [*.data*] files found
26     in the [kernels/] subdirectory (ie. the kerneldb).
27 *)
28
29 (** {2 Types} *)
30
31 type pathname = string
32   (** Path and filenames. *)
33
34 type info = {
35   kernel_version : string;             (** Kernel version that this matches. *)
36   arch : string;                       (** Architecture, eg. "i686", "ppc64". *)
37   basename : string;                   (** [basename.info] is the info
38                                            file and [basename.data*] is
39                                            the data file. *)
40 }
41   (** Kernel metainformation, extracted from the [*.info] file. *)
42
43 type structure = {
44   struct_name : string;                 (** Structure name. *)
45   struct_total_size : int;              (** Total size in bytes. *)
46   struct_fields : field list;           (** Fields in the structure. *)
47 }
48   (** A kernel structure, eg. [task_struct]. *)
49
50 and field = {
51   field_name : string;                  (** Field name. *)
52   field_type : f_type;                  (** Field type. *)
53   field_offset : int;                   (** Offset within the structure. *)
54   field_size : int;                     (** Size of the field (bytes). *)
55 }
56   (** A kernel structure field.
57
58       Note that nested fields are flattened with single quotes (')
59       between elements, so you get names like [tasks'next]. *)
60
61 and f_type =
62   | FStructPointer of string            (** A pointer to a named struct. *)
63   | FVoidPointer                        (** A [void*] pointer. *)
64   | FListHeadPointer                    (** A pointer to a [list_head]. *)
65   | FInteger                            (** An integer. *)
66   | FString of int                      (** A char array of given width. *)
67   (** Type of a kernel field. *)
68
69 val string_of_info : info -> string
70 val string_of_structure : structure -> string
71 val string_of_field : field -> string
72 val string_of_f_type : f_type -> string
73   (** Printing functions. *)
74
75 (** {2 List kernels in kerneldb} *)
76
77 val list_kernels : pathname -> info list
78   (** Return a list of all the kernels in the kerneldb at [path]. *)
79
80 (** {2 Load kernel structures} *)
81
82 val load_structures : info -> string list -> structure list
83   (** [load_structures info names] loads the named kernel structures
84       from a particular kernel.
85
86       The returned list is not necessarily in the same order, or the
87       same length, as the [names] list.  Check the
88       {!structure.struct_name} field for the structure name.
89       Structures which don't actually occur in the given kernel are
90       not loaded and not present in the final list.
91   *)