From: Yonghong Song <yhs@fb.com>
To: Arnaldo Carvalho de Melo <arnaldo.melo@gmail.com>,
<dwarves@vger.kernel.org>
Cc: Alexei Starovoitov <ast@kernel.org>,
Andrii Nakryiko <andrii@kernel.org>,
Bill Wendling <morbo@google.com>, <bpf@vger.kernel.org>,
<kernel-team@fb.com>
Subject: [PATCH dwarves 2/3] dwarf_loader: factor out common code to initialize a cu
Date: Wed, 24 Mar 2021 23:53:27 -0700 [thread overview]
Message-ID: <20210325065327.3122071-1-yhs@fb.com> (raw)
In-Reply-To: <20210325065316.3121287-1-yhs@fb.com>
Both cus__load_debug_types() and cus__load_module()
created new cu's followed by initialization. The
initialization codes are identical so let us refactor
into a common function which can be used later as
well when dealing with merging cu's.
Signed-off-by: Yonghong Song <yhs@fb.com>
---
dwarf_loader.c | 45 ++++++++++++++++++++-------------------------
1 file changed, 20 insertions(+), 25 deletions(-)
diff --git a/dwarf_loader.c b/dwarf_loader.c
index a02ef23..dc66df0 100644
--- a/dwarf_loader.c
+++ b/dwarf_loader.c
@@ -2411,6 +2411,23 @@ static int finalize_cu_immediately(struct cus *cus, struct cu *cu,
return lsk;
}
+static int cu__set_common(struct cu *cu, struct conf_load *conf,
+ Dwfl_Module *mod, Elf *elf)
+{
+ cu->uses_global_strings = true;
+ cu->elf = elf;
+ cu->dwfl = mod;
+ cu->extra_dbg_info = conf ? conf->extra_dbg_info : 0;
+ cu->has_addr_info = conf ? conf->get_addr_info : 0;
+
+ GElf_Ehdr ehdr;
+ if (gelf_getehdr(elf, &ehdr) == NULL)
+ return DWARF_CB_ABORT;
+
+ cu->little_endian = ehdr.e_ident[EI_DATA] == ELFDATA2LSB;
+ return 0;
+}
+
static int cus__load_debug_types(struct cus *cus, struct conf_load *conf,
Dwfl_Module *mod, Dwarf *dw, Elf *elf,
const char *filename,
@@ -2434,22 +2451,11 @@ static int cus__load_debug_types(struct cus *cus, struct conf_load *conf,
cu = cu__new("", pointer_size, build_id,
build_id_len, filename);
- if (cu == NULL) {
+ if (cu == NULL ||
+ cu__set_common(cu, conf, mod, elf) != 0) {
return DWARF_CB_ABORT;
}
- cu->uses_global_strings = true;
- cu->elf = elf;
- cu->dwfl = mod;
- cu->extra_dbg_info = conf ? conf->extra_dbg_info : 0;
- cu->has_addr_info = conf ? conf->get_addr_info : 0;
-
- GElf_Ehdr ehdr;
- if (gelf_getehdr(elf, &ehdr) == NULL) {
- return DWARF_CB_ABORT;
- }
- cu->little_endian = ehdr.e_ident[EI_DATA] == ELFDATA2LSB;
-
if (dwarf_cu__init(dcup) != 0)
return DWARF_CB_ABORT;
@@ -2528,19 +2534,8 @@ static int cus__load_module(struct cus *cus, struct conf_load *conf,
const char *name = attr_string(cu_die, DW_AT_name);
struct cu *cu = cu__new(name ?: "", pointer_size,
build_id, build_id_len, filename);
- if (cu == NULL)
- return DWARF_CB_ABORT;
- cu->uses_global_strings = true;
- cu->elf = elf;
- cu->dwfl = mod;
- cu->extra_dbg_info = conf ? conf->extra_dbg_info : 0;
- cu->has_addr_info = conf ? conf->get_addr_info : 0;
-
- GElf_Ehdr ehdr;
- if (gelf_getehdr(elf, &ehdr) == NULL) {
+ if (cu == NULL || cu__set_common(cu, conf, mod, elf) != 0)
return DWARF_CB_ABORT;
- }
- cu->little_endian = ehdr.e_ident[EI_DATA] == ELFDATA2LSB;
struct dwarf_cu dcu;
--
2.30.2
next prev parent reply other threads:[~2021-03-25 6:54 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-25 6:53 [PATCH dwarves 0/3] add option to merge more dwarf cu's into Yonghong Song
2021-03-25 6:53 ` [PATCH dwarves 1/3] dwarf_loader: permits flexible HASHTAGS__BITS Yonghong Song
2021-03-26 23:13 ` Andrii Nakryiko
2021-03-26 23:26 ` Yonghong Song
2021-03-29 14:02 ` Arnaldo Carvalho de Melo
2021-03-31 4:30 ` Andrii Nakryiko
2021-03-25 6:53 ` Yonghong Song [this message]
2021-03-25 6:53 ` [PATCH dwarves 3/3] dwarf_loader: add option to merge more dwarf cu's into one pahole cu Yonghong Song
2021-03-26 14:41 ` Arnaldo Carvalho de Melo
2021-03-26 15:18 ` Yonghong Song
2021-03-26 17:35 ` Arnaldo Carvalho de Melo
2021-03-26 18:19 ` Arnaldo Carvalho de Melo
2021-03-26 23:05 ` Yonghong Song
2021-03-26 23:12 ` Alexei Starovoitov
2021-03-26 23:17 ` Yonghong Song
2021-03-29 14:04 ` Arnaldo Carvalho de Melo
2021-03-26 15:18 ` Arnaldo Carvalho de Melo
2021-03-26 23:21 ` Andrii Nakryiko
2021-03-27 0:19 ` Yonghong Song
2021-03-25 13:10 ` [PATCH dwarves 0/3] add option to merge more dwarf cu's into Arnaldo Carvalho de Melo
2021-03-26 1:41 ` Yonghong Song
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210325065327.3122071-1-yhs@fb.com \
--to=yhs@fb.com \
--cc=andrii@kernel.org \
--cc=arnaldo.melo@gmail.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=dwarves@vger.kernel.org \
--cc=kernel-team@fb.com \
--cc=morbo@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.