1 (** 'pahole' output parser. *)
2 (* Memory info command for virtual domains.
3 (C) Copyright 2008 Richard W.M. Jones, Red Hat Inc.
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.
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.
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.
21 (** This parses the output of the pahole command, allowing us
22 to extract the layout of kernel structures for particular
25 Its primary input is the [*.info] and [*.data*] files found
26 in the [kernels/] subdirectory (ie. the kerneldb).
31 type pathname = string
32 (** Path and filenames. *)
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
41 (** Kernel metainformation, extracted from the [*.info] file. *)
44 struct_name : string; (** Structure name. *)
45 struct_total_size : int; (** Total size in bytes. *)
46 struct_fields : field list; (** Fields in the structure. *)
48 (** A kernel structure, eg. [task_struct]. *)
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). *)
56 (** A kernel structure field.
58 Note that nested fields are flattened with single quotes (')
59 between elements, so you get names like [tasks'next]. *)
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. *)
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. *)
75 (** {2 List kernels in kerneldb} *)
77 val list_kernels : pathname -> info list
78 (** Return a list of all the kernels in the kerneldb at [path]. *)
80 (** {2 Load kernel structures} *)
82 val load_structures : info -> string list -> structure list
83 (** [load_structures info names] loads the named kernel structures
84 from a particular kernel.
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.