Skip to content

Commit bb54cad

Browse files
author
Delphix Engineering
committed
Merge branch 'refs/heads/upstream-HEAD' into repo-HEAD
2 parents 60e015a + 4de147e commit bb54cad

File tree

14 files changed

+225
-174
lines changed

14 files changed

+225
-174
lines changed

CONTRIBUTING.rst

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
Contributing
2+
============
3+
4+
Thanks for your interest in drgn! See below for how to build, test, code, and
5+
submit changes for drgn.
6+
7+
Building
8+
--------
9+
10+
The easiest way to develop drgn is by building and running it locally. See the
11+
`installation documentation
12+
<https://drgn.readthedocs.io/en/latest/installation.html#development>`_.
13+
14+
Testing
15+
-------
16+
17+
.. highlight:: console
18+
19+
Tests should be added for all features and bug fixes.
20+
21+
drgn's test suite can be run with::
22+
23+
$ python3 setup.py test
24+
25+
To run Linux kernel helper tests in a virtual machine on all supported kernels,
26+
add ``-K``. See `vmtest <vmtest/README.rst>`_ for more details.
27+
28+
Tests can also be run manually with `unittest
29+
<https://docs.python.org/3/library/unittest.html#command-line-interface>`_
30+
after building locally::
31+
32+
$ python3 -m unittest discover -v
33+
34+
To run Linux kernel helper tests on the running kernel, this must be run as
35+
root, and debug information for the running kernel must be available.
36+
37+
Coding Guidelines
38+
-----------------
39+
40+
* Core functionality should be implemented in ``libdrgn`` and exposed to Python
41+
via the `C extension <libdrgn/python>`_. Only the CLI and helpers should be
42+
in pure Python.
43+
* Linux kernel helpers should work on all supported kernels if possible.
44+
45+
C
46+
^
47+
48+
C code in drgn mostly follows the `Linux kernel coding style
49+
<https://www.kernel.org/doc/html/latest/process/coding-style.html>`_ except
50+
that drgn requires C11 or newer, so declarations may be mixed with code.
51+
52+
A few other guidelines:
53+
54+
* Functions that can fail should return a ``struct drgn_error *`` (and return
55+
their result via an out parameter if necessary).
56+
* Out parameters should be named ``ret`` (or suffixed with ``_ret`` if there
57+
are multiple).
58+
* Constants should be defined as enums or ``static const`` variables rather
59+
than macros.
60+
61+
drgn assumes some `implementation-defined behavior
62+
<https://gcc.gnu.org/onlinedocs/gcc/C-Implementation.html>`_ for sanity:
63+
64+
* Signed integers are represented with two's complement.
65+
* Bitwise operators on signed integers operate on the two's complement
66+
representation.
67+
* Right shift of a signed integer type is arithmetic.
68+
* Conversion to a signed integer type is modular.
69+
* Casting between pointers and integers does not change the bit representation.
70+
71+
Python
72+
^^^^^^
73+
74+
Python code in drgn is formatted with `black <https://github.com/psf/black>`_.
75+
Code should be compatible with Python 3.6 and newer.
76+
77+
Type hints should be provided for all public interfaces other than helpers
78+
(including the C extension) and most private interfaces.
79+
80+
Submitting PRs
81+
--------------
82+
83+
Pull requests and issues are always welcome. Feel free to start a discussion
84+
with a prototype.
85+
86+
All commits must be signed off (i.e., ``Signed-off-by: Jane Doe
87+
<[email protected]>``) as per the `Developer Certificate of Origin
88+
<https://developercertificate.org/>`_. ``git commit -s`` can do this for you.

README.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ Installation
5656

5757
.. start-install-dependencies
5858
59+
.. highlight:: console
60+
5961
Install dependencies:
6062

6163
Arch Linux::
@@ -81,9 +83,7 @@ Optionally, install:
8183

8284
.. end-install-dependencies
8385
84-
Then, run:
85-
86-
.. code-block:: console
86+
Then, run::
8787

8888
$ sudo pip3 install drgn
8989

docs/installation.rst

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
Installation
22
============
33

4-
.. highlight:: console
4+
There are several options for installing drgn.
5+
6+
Dependencies
7+
------------
58

69
drgn depends on:
710

@@ -30,8 +33,13 @@ The build requires:
3033
:start-after: start-install-dependencies
3134
:end-before: end-install-dependencies
3235

33-
The latest release of drgn can be installed globally with `pip
34-
<https://pip.pypa.io>`_::
36+
Installation
37+
------------
38+
39+
.. highlight:: console
40+
41+
After installing dependencies, the latest release of drgn can be installed
42+
globally with `pip <https://pip.pypa.io>`_::
3543

3644
$ sudo pip3 install drgn
3745
$ drgn --help
@@ -53,9 +61,12 @@ drgn globally::
5361
(drgenv) $ pip3 install drgn
5462
(drgenv) $ drgn --help
5563

64+
Development
65+
-----------
66+
5667
For development, drgn can be built and run locally::
5768

58-
$ python3 setup.py egg_info build_ext -i
69+
$ CFLAGS="-Wall -Werror -g -O2" python3 setup.py egg_info build_ext -i
5970
$ python3 -m drgn --help
6071

6172
libkdumpfile

libdrgn/dwarf_index.c

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -242,11 +242,7 @@ struct abbrev_table {
242242
struct uint8_vector insns;
243243
};
244244

245-
static void abbrev_table_init(struct abbrev_table *abbrev)
246-
{
247-
uint32_vector_init(&abbrev->decls);
248-
uint8_vector_init(&abbrev->insns);
249-
}
245+
#define ABBREV_TABLE_INIT { VECTOR_INIT, VECTOR_INIT }
250246

251247
static void abbrev_table_deinit(struct abbrev_table *abbrev)
252248
{
@@ -1310,12 +1306,10 @@ static struct drgn_error *read_cus(struct drgn_dwarf_index *dindex,
13101306

13111307
#pragma omp parallel
13121308
{
1313-
struct compilation_unit_vector cus;
1314-
size_t i;
1309+
struct compilation_unit_vector cus = VECTOR_INIT;
13151310

1316-
compilation_unit_vector_init(&cus);
13171311
#pragma omp for schedule(dynamic)
1318-
for (i = 0; i < num_unindexed; i++) {
1312+
for (size_t i = 0; i < num_unindexed; i++) {
13191313
struct drgn_error *module_err;
13201314
const char *name;
13211315

@@ -1723,25 +1717,22 @@ read_file_name_table(struct drgn_dwarf_index *dindex,
17231717
Elf_Data *debug_line = cu->sections[SECTION_DEBUG_LINE];
17241718
const char *ptr = section_ptr(debug_line, stmt_list);
17251719
const char *end = section_end(debug_line);
1726-
struct siphash_vector directories;
1727-
1728-
siphash_vector_init(&directories);
17291720

17301721
err = skip_lnp_header(cu, &ptr, end);
17311722
if (err)
17321723
return err;
17331724

1725+
struct siphash_vector directories = VECTOR_INIT;
17341726
for (;;) {
1735-
struct siphash *hash;
17361727
const char *path;
17371728
size_t path_len;
1738-
17391729
if (!read_string(&ptr, end, &path, &path_len))
17401730
return drgn_eof();
17411731
if (!path_len)
17421732
break;
17431733

1744-
hash = siphash_vector_append_entry(&directories);
1734+
struct siphash *hash =
1735+
siphash_vector_append_entry(&directories);
17451736
if (!hash) {
17461737
err = &drgn_enomem;
17471738
goto out;
@@ -1753,17 +1744,14 @@ read_file_name_table(struct drgn_dwarf_index *dindex,
17531744
for (;;) {
17541745
const char *path;
17551746
size_t path_len;
1756-
uint64_t directory_index;
1757-
struct siphash hash;
1758-
uint64_t file_name_hash;
1759-
17601747
if (!read_string(&ptr, end, &path, &path_len)) {
17611748
err = drgn_eof();
17621749
goto out;
17631750
}
17641751
if (!path_len)
17651752
break;
17661753

1754+
uint64_t directory_index;
17671755
if ((err = read_uleb128(&ptr, end, &directory_index)))
17681756
goto out;
17691757
/* mtime, size */
@@ -1779,13 +1767,14 @@ read_file_name_table(struct drgn_dwarf_index *dindex,
17791767
goto out;
17801768
}
17811769

1770+
struct siphash hash;
17821771
if (directory_index)
17831772
hash = directories.data[directory_index - 1];
17841773
else
17851774
siphash_init(&hash, siphash_key);
17861775
siphash_update(&hash, path, path_len);
17871776

1788-
file_name_hash = siphash_final(&hash);
1777+
uint64_t file_name_hash = siphash_final(&hash);
17891778
if (!uint64_vector_append(file_name_table, &file_name_hash)) {
17901779
err = &drgn_enomem;
17911780
goto out;
@@ -2059,8 +2048,8 @@ static struct drgn_error *index_cu(struct drgn_dwarf_index *dindex,
20592048
struct compilation_unit *cu)
20602049
{
20612050
struct drgn_error *err;
2062-
struct abbrev_table abbrev;
2063-
struct uint64_vector file_name_table;
2051+
struct abbrev_table abbrev = ABBREV_TABLE_INIT;
2052+
struct uint64_vector file_name_table = VECTOR_INIT;
20642053
Elf_Data *debug_abbrev = cu->sections[SECTION_DEBUG_ABBREV];
20652054
const char *debug_abbrev_end = section_end(debug_abbrev);
20662055
const char *ptr = &cu->ptr[cu->is_64_bit ? 23 : 11];
@@ -2073,9 +2062,6 @@ static struct drgn_error *index_cu(struct drgn_dwarf_index *dindex,
20732062
unsigned int depth = 0;
20742063
uint64_t enum_die_offset = 0;
20752064

2076-
abbrev_table_init(&abbrev);
2077-
uint64_vector_init(&file_name_table);
2078-
20792065
if ((err = read_abbrev_table(section_ptr(debug_abbrev,
20802066
cu->debug_abbrev_offset),
20812067
debug_abbrev_end, cu, &abbrev)))
@@ -2265,8 +2251,8 @@ drgn_dwarf_index_report_end_internal(struct drgn_dwarf_index *dindex,
22652251
bool report_from_dwfl)
22662252
{
22672253
struct drgn_error *err;
2268-
struct drgn_dwarf_module_vector unindexed;
2269-
struct compilation_unit_vector cus;
2254+
struct drgn_dwarf_module_vector unindexed = VECTOR_INIT;
2255+
struct compilation_unit_vector cus = VECTOR_INIT;
22702256

22712257
dwfl_report_end(dindex->dwfl, NULL, NULL);
22722258
if (report_from_dwfl &&
@@ -2275,8 +2261,6 @@ drgn_dwarf_index_report_end_internal(struct drgn_dwarf_index *dindex,
22752261
err = &drgn_enomem;
22762262
goto err;
22772263
}
2278-
drgn_dwarf_module_vector_init(&unindexed);
2279-
compilation_unit_vector_init(&cus);
22802264
err = drgn_dwarf_index_get_unindexed(dindex, &unindexed);
22812265
if (err)
22822266
goto err;

0 commit comments

Comments
 (0)