• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..--

examples/29-Jul-2022-2,9721,567

MakefileD29-Jul-20226.7 KiB195130

README.pretty-printersD29-Jul-20226.6 KiB176135

README.tunablesD29-Jul-20225.1 KiB155108

argp.texiD29-Jul-202252.9 KiB1,3221,107

arith.texiD29-Jul-2022140.7 KiB3,3162,839

charset.texiD29-Jul-2022129 KiB2,9622,528

check-safety.shD29-Jul-20224.5 KiB12546

conf.texiD29-Jul-202256.2 KiB1,6371,314

contrib.texiD29-Jul-202215.6 KiB569428

creature.texiD29-Jul-202213.7 KiB339280

crypt.texiD29-Jul-202214.3 KiB345285

ctype.texiD29-Jul-202226.9 KiB808666

debug.texiD29-Jul-20226.5 KiB134115

dirD29-Jul-2022544 1612

dynlink.texiD29-Jul-20228.3 KiB216174

errno.texiD29-Jul-202256.3 KiB1,5701,328

fdl-1.3.texiD29-Jul-202222.9 KiB506421

filesys.texiD29-Jul-2022141.1 KiB3,6002,954

freemanuals.texiD29-Jul-20224.8 KiB9480

getopt.texiD29-Jul-202212.9 KiB324264

header.texiD29-Jul-2022755 2320

install-plain.texiD29-Jul-2022183 65

install.texiD29-Jul-202236 KiB788655

intro.texiD29-Jul-202263.2 KiB1,5061,216

io.texiD29-Jul-202217 KiB396321

ipc.texiD29-Jul-20224 KiB11796

job.texiD29-Jul-202245.4 KiB1,2881,068

lang.texiD29-Jul-202247.3 KiB1,2291,000

lgpl-2.1.texiD29-Jul-202225.9 KiB550463

libc-texinfo.shD29-Jul-20222.3 KiB8868

libc.texinfoD29-Jul-20224.5 KiB169133

libcbook.texiD29-Jul-202247 43

llio.texiD29-Jul-2022185.9 KiB4,6263,779

locale.texiD29-Jul-202258.4 KiB1,4841,271

macros.texiD29-Jul-20227.5 KiB286261

maint.texiD29-Jul-202226.9 KiB656546

math.texiD29-Jul-202285.5 KiB2,0591,778

memory.texiD29-Jul-2022145.3 KiB3,7413,107

message.texiD29-Jul-202278.5 KiB1,9601,628

nss.texiD29-Jul-202229.4 KiB745607

nsswitch.texiD29-Jul-2022254 1713

pattern.texiD29-Jul-202291.2 KiB2,2381,941

pipe.texiD29-Jul-202213.4 KiB320281

platform.texiD29-Jul-202216.6 KiB707500

probes.texiD29-Jul-202214 KiB295253

process.texiD29-Jul-202235.2 KiB888740

resource.texiD29-Jul-202261.7 KiB1,6381,300

search.texiD29-Jul-202228.6 KiB650554

setjmp.texiD29-Jul-202222.1 KiB491412

signal.texiD29-Jul-2022130.4 KiB3,3392,776

socket.texiD29-Jul-2022153.6 KiB3,6673,092

startup.texiD29-Jul-202242.3 KiB1,076859

stdio-fp.cD29-Jul-2022392 2921

stdio.texiD29-Jul-2022227.5 KiB5,5264,568

string.texiD29-Jul-2022118.9 KiB2,8992,422

summary.plD29-Jul-202212.8 KiB403272

sysinfo.texiD29-Jul-202244.2 KiB1,109895

syslog.texiD29-Jul-202221.3 KiB574454

terminal.texiD29-Jul-202283.3 KiB2,2371,861

texinfo.texD29-Jul-2022371.3 KiB11,67310,859

texis.awkD29-Jul-2022316 2221

threads.texiD29-Jul-202243.8 KiB1,160979

time.texiD29-Jul-2022120.9 KiB3,0572,498

tsort.awkD29-Jul-2022695 4640

tunables.texiD29-Jul-202226.2 KiB615506

users.texiD29-Jul-2022116.7 KiB2,7662,383

xtract-typefun.awkD29-Jul-2022867 4433

README.pretty-printers

1README for the glibc Python pretty printers
2===========================================
3
4Pretty printers are gdb extensions that allow it to print useful, human-readable
5information about a program's variables.  For example, for a pthread_mutex_t
6gdb would usually output something like this:
7
8(gdb) print mutex
9$1 = {
10  __data = {
11    __lock = 22020096,
12    __count = 0,
13    __owner = 0,
14    __nusers = 0,
15    __kind = 576,
16    __spins = 0,
17    __elision = 0,
18    __list = {
19      __prev = 0x0,
20      __next = 0x0
21    }
22  },
23  __size = "\000\000P\001", '\000' <repeats 12 times>, "@\002", '\000' <repeats 21 times>,
24  __align = 22020096
25}
26
27However, with a pretty printer gdb will output something like this:
28
29(gdb) print mutex
30$1 = pthread_mutex_t = {
31  Type = Normal,
32  Status = Not acquired,
33  Robust = No,
34  Shared = No,
35  Protocol = Priority protect,
36  Priority ceiling = 42
37}
38
39Before printing a value, gdb will first check if there's a pretty printer
40registered for it.  If there is, it'll use it, otherwise it'll print the value
41as usual.  Pretty printers can be registered in various ways; for our purposes
42we register them for the current objfile by calling
43gdb.printing.register_pretty_printer().
44
45Currently our printers are based on gdb.RegexpCollectionPrettyPrinter, which
46means they'll be triggered if the type of the variable we're printing matches
47a given regular expression.  For example, MutexPrinter will be triggered if
48our variable's type matches the regexp '^pthread_mutex_t$'.
49
50Besides the printers themselves, each module may have a constants file which the
51printers will import.  These constants are generated from C headers during the
52build process, and need to be in the Python search path when loading the
53printers.
54
55
56Installing and loading
57----------------------
58
59The pretty printers and their constant files may be installed in different paths
60for each distro, though gdb should be able to automatically load them by itself.
61When in doubt, you can use the 'info pretty-printer' gdb command to list the
62loaded pretty printers.
63
64If the printers aren't automatically loaded for some reason, you should add the
65following to your .gdbinit:
66
67python
68import sys
69sys.path.insert(0, '/path/to/constants/file/directory')
70end
71
72source /path/to/printers.py
73
74If you're building glibc manually, '/path/to/constants/file/directory' should be
75'/path/to/glibc-build/submodule', where 'submodule' is e.g. nptl.
76
77
78Testing
79-------
80
81The pretty printers come with a small test suite based on PExpect, which is a
82Python module with Expect-like features for spawning and controlling interactive
83programs.  Each printer has a corresponding C program and a Python script
84that uses PExpect to drive gdb through the program and compare its output to
85the expected printer's.
86
87The tests run on the glibc host, which is assumed to have both gdb and PExpect;
88if any of those is absent the tests will fail with code 77 (UNSUPPORTED).
89Native builds can be tested simply by doing 'make check'; cross builds must use
90cross-test-ssh.sh as test-wrapper, like this:
91
92make test-wrapper='/path/to/scripts/cross-test-ssh.sh user@host' check
93
94(Remember to share the build system's filesystem with the glibc host's through
95NFS or something similar).
96
97Running 'make check' on a cross build will only compile the test programs,
98without running the scripts.
99
100
101Adding new pretty printers
102--------------------------
103
104Adding new pretty printers to glibc requires following these steps:
105
1061. Identify which constants must be generated from C headers, and write the
107corresponding .pysym file.  See scripts/gen-as-const.py for more information
108on how this works.  The name of the .pysym file must be added to the
109'gen-py-const-headers' variable in your submodule's Makefile (without the .pysym
110extension).
111
1122. Write the pretty printer code itself.  For this you can follow the gdb
113Python API documentation, and use the existing printers as examples.  The printer
114code must import the generated constants file (which will have the same name
115as your .pysym file).  The names of the pretty printer files must be added
116to the 'pretty-printers' variable in your submodule's Makefile (without the .py
117extension).
118
1193. Write the unit tests for your pretty printers.  The build system calls each
120test script passing it the paths to the test program source, the test program
121binary, and the printer files you added to 'pretty-printers' in the previous
122step.  The test scripts, in turn, must import scripts/test_printers_common
123and call the init_test function passing it, among other things, the name of the
124set of pretty printers to enable (as seen by running 'info pretty-printer').
125You can use the existing unit tests as examples.
126
1274. Add the names of the pretty printer tests to the 'tests-printers' variable
128in your submodule's Makefile (without extensions).  In addition, for each test
129program you must define a corresponding CFLAGS-* and CPPFLAGS-* variable and
130set it to $(CFLAGS-printers-tests) to ensure they're compiled correctly.  For
131example, test-foo-printer.c requires the following:
132
133CFLAGS-test-foo-printer.c := $(CFLAGS-printers-tests)
134CPPFLAGS-test-foo-printer.c := $(CFLAGS-printers-tests)
135
136Finally, if your programs need to be linked with a specific library, you can add
137its name to the 'tests-printers-libs' variable in your submodule's Makefile.
138
139
140Known issues
141------------
142
143* Pretty printers are inherently coupled to the code they're targetting, thus
144any changes to the target code must also update the corresponding printers.
145On the plus side, the printer code itself may serve as a kind of documentation
146for the target code.
147
148* There's no guarantee that the information the pretty printers provide is
149complete, i.e. some details might be left off.  For example, the pthread_mutex_t
150printers won't report whether a thread is spin-waiting in an attempt to acquire
151the mutex.
152
153* Older versions of the gdb Python API have a bug where
154gdb.RegexpCollectionPrettyPrinter would not be able to get a value's real type
155if it was typedef'd.  This would cause gdb to ignore the pretty printers for
156types like pthread_mutex_t, which is defined as:
157
158typedef union
159{
160  ...
161} pthread_mutex_t;
162
163This was fixed in commit 1b588015839caafc608a6944a78aea170f5fb2f6, and released
164as part of gdb 7.8.  However, typedef'ing an already typedef'd type may cause
165a similar issue, e.g.:
166
167typedef pthread_mutex_t mutex;
168mutex a_mutex;
169
170Here, trying to print a_mutex won't trigger the pthread_mutex_t printer.
171
172* The test programs must be compiled without optimizations.  This is necessary
173because the test scripts rely on the C code structure being preserved when
174stepping through the programs.  Things like aggressive instruction reordering
175or optimizing variables out may make this kind of testing impossible.
176

README.tunables

1			TUNABLE FRAMEWORK
2			=================
3
4Tunables is a feature in the GNU C Library that allows application authors and
5distribution maintainers to alter the runtime library behaviour to match their
6workload.
7
8The tunable framework allows modules within glibc to register variables that
9may be tweaked through an environment variable.  It aims to enforce a strict
10namespace rule to bring consistency to naming of these tunable environment
11variables across the project.  This document is a guide for glibc developers to
12add tunables to the framework.
13
14ADDING A NEW TUNABLE
15--------------------
16
17The TOP_NAMESPACE macro is defined by default as 'glibc'.  If distributions
18intend to add their own tunables, they should do so in a different top
19namespace by overriding the TOP_NAMESPACE macro for that tunable.  Downstream
20implementations are discouraged from using the 'glibc' top namespace for
21tunables they don't already have consensus to push upstream.
22
23There are three steps to adding a tunable:
24
251. Add a tunable to the list and fully specify its properties:
26
27For each tunable you want to add, make an entry in elf/dl-tunables.list.  The
28format of the file is as follows:
29
30TOP_NAMESPACE {
31  NAMESPACE1 {
32    TUNABLE1 {
33      # tunable attributes, one per line
34    }
35    # A tunable with default attributes, i.e. string variable.
36    TUNABLE2
37    TUNABLE3 {
38      # its attributes
39    }
40  }
41  NAMESPACE2 {
42    ...
43  }
44}
45
46The list of allowed attributes are:
47
48- type:			Data type.  Defaults to STRING.  Allowed types are:
49			INT_32, UINT_64, SIZE_T and STRING.  Numeric types may
50			be in octal or hexadecimal format too.
51
52- minval:		Optional minimum acceptable value.  For a string type
53			this is the minimum length of the value.
54
55- maxval:		Optional maximum acceptable value.  For a string type
56			this is the maximum length of the value.
57
58- default:		Specify an optional default value for the tunable.
59
60- env_alias:		An alias environment variable
61
62- security_level:	Specify security level of the tunable for AT_SECURE
63			binaries.  Valid values are:
64
65			SXID_ERASE: (default) Do not read and do not pass on to
66			child processes.
67			SXID_IGNORE: Do not read, but retain for non-AT_SECURE
68			child processes.
69			NONE: Read all the time.
70
712. Use TUNABLE_GET/TUNABLE_SET/TUNABLE_SET_WITH_BOUNDS to get and set tunables.
72
733. OPTIONAL: If tunables in a namespace are being used multiple times within a
74   specific module, set the TUNABLE_NAMESPACE macro to reduce the amount of
75   typing.
76
77GETTING AND SETTING TUNABLES
78----------------------------
79
80When the TUNABLE_NAMESPACE macro is defined, one may get tunables in that
81module using the TUNABLE_GET macro as follows:
82
83  val = TUNABLE_GET (check, int32_t, TUNABLE_CALLBACK (check_callback))
84
85where 'check' is the tunable name, 'int32_t' is the C type of the tunable and
86'check_callback' is the function to call if the tunable got initialized to a
87non-default value.  The macro returns the value as type 'int32_t'.
88
89The callback function should be defined as follows:
90
91  void
92  TUNABLE_CALLBACK (check_callback) (int32_t *valp)
93  {
94  ...
95  }
96
97where it can expect the tunable value to be passed in VALP.
98
99Tunables in the module can be updated using:
100
101  TUNABLE_SET (check, val)
102
103where 'check' is the tunable name and 'val' is a value of same type.
104
105To get and set tunables in a different namespace from that module, use the full
106form of the macros as follows:
107
108  val = TUNABLE_GET_FULL (glibc, cpu, hwcap_mask, uint64_t, NULL)
109
110  TUNABLE_SET_FULL (glibc, cpu, hwcap_mask, val)
111
112where 'glibc' is the top namespace, 'cpu' is the tunable namespace and the
113remaining arguments are the same as the short form macros.
114
115The minimum and maximum values can updated together with the tunable value
116using:
117
118  TUNABLE_SET_WITH_BOUNDS (check, val, min, max)
119
120where 'check' is the tunable name, 'val' is a value of same type, 'min' and
121'max' are the minimum and maximum values of the tunable.
122
123To set the minimum and maximum values of tunables in a different namespace
124from that module, use the full form of the macros as follows:
125
126  val = TUNABLE_GET_FULL (glibc, cpu, hwcap_mask, uint64_t, NULL)
127
128  TUNABLE_SET_WITH_BOUNDS_FULL (glibc, cpu, hwcap_mask, val, min, max)
129
130where 'glibc' is the top namespace, 'cpu' is the tunable namespace and the
131remaining arguments are the same as the short form macros.
132
133When TUNABLE_NAMESPACE is not defined in a module, TUNABLE_GET is equivalent to
134TUNABLE_GET_FULL, so you will need to provide full namespace information for
135both macros.  Likewise for TUNABLE_SET, TUNABLE_SET_FULL,
136TUNABLE_SET_WITH_BOUNDS and TUNABLE_SET_WITH_BOUNDS_FULL.
137
138** IMPORTANT NOTE **
139
140The tunable list is set as read-only after the dynamic linker relocates itself,
141so setting tunable values must be limited only to tunables within the dynamic
142linker, that too before relocation.
143
144FUTURE WORK
145-----------
146
147The framework currently only allows a one-time initialization of variables
148through environment variables and in some cases, modification of variables via
149an API call.  A future goals for this project include:
150
151- Setting system-wide and user-wide defaults for tunables through some
152  mechanism like a configuration file.
153
154- Allow tweaking of some tunables at runtime
155