blob: 3dd7601488435880cdde14012271c7ad948f95f2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
This document is a brief description of the main
coding style conventions in libdwarf. Many of them
will be obvious from the code, but over time some
accidental diffences crept in.
Code should be indented in multiples of 4 spaces, and
tabs should not be used to indent the source code.
Use the dicheck program to check indenting.
dwarf.h and libdwarf.h must have all arguments commented
out as these are public headers. Because a prototype like
int dwarf_example_prototype(Dwarf_Debug foo);
would be made unusable by a legitimate
preprocessor definition
such as #define foo +
The struct naming convention is 'struct Camel_Caps_s' for the
struct and 'Camel_Caps' for any typedef for the struct.
Admittedly having both camel caps
and an underbar is an unusual convention, but it is
the way the coding was begun in the early 1990's and
we should remain consistent now.
All user-referenceable data and functions
and user_visible types should begin with DW_ or
dwarf_. Non-static libdwarf global data and functions
should begin with _dwarf (a somewhat questionable
approach, but workable).
Function names should be all lower case with underbars
for readability.
There should never be static data in any function.
Nor should there ever be static data outside of libdwarf
functions. libdwarf can be called from multiple threads
(but only from one thread per Dwarf_Debug) and multiple
Dwarf_Debug objects can be open at one time.
Instead place such data per-dbg into the Dwarf_Debug structure
in dwarf_opaque.h. Similarly for the producer code.
Function-local variables should be lower-case with
underbars for readability. It's ok for a small loop
with counters to use single letter names like i or k or m.
structure members should have a struct-specific
2-character prefix to the name (followed by
an underbar). That makes it much
easier to grep for uses of members.
Try to keep lines under 80 characters in length.
Ensure every if() has {} to enclose the actions.
Use libdwarf.h types for all the data objects you define,
though sometimes an 'unsigned' or 'int' or 'size_t' is
ok in restricted circumstances. Dwarf_Unsigned Dwarf_Signed
are the preferred integer types for general use.
------------
|