diff options
author | Martin Liska <mliska@suse.cz> | 2021-04-19 14:33:36 +0200 |
---|---|---|
committer | Mark Wielaard <mark@klomp.org> | 2021-05-12 11:56:57 +0200 |
commit | adc201f81902f3015a841869756ed4b9b811fe33 (patch) | |
tree | 735ab647b6e749f7bbbd1cd88256f89c2de266a9 /libdwfl | |
parent | elfutils.spec: Add procps as a %check BuildRequires:. (diff) | |
download | elfutils-adc201f81902f3015a841869756ed4b9b811fe33.tar.gz elfutils-adc201f81902f3015a841869756ed4b9b811fe33.tar.bz2 elfutils-adc201f81902f3015a841869756ed4b9b811fe33.tar.xz |
Come up with startswith function.
New function in system.h that returns true if a string has a given
prefix, false otherwise. Use it in place of strncmp.
Signed-off-by: Martin Liška <mliska@suse.cz>
Diffstat (limited to 'libdwfl')
-rw-r--r-- | libdwfl/ChangeLog | 10 | ||||
-rw-r--r-- | libdwfl/dwfl_frame.c | 4 | ||||
-rw-r--r-- | libdwfl/dwfl_module_getdwarf.c | 4 | ||||
-rw-r--r-- | libdwfl/linux-kernel-modules.c | 4 | ||||
-rw-r--r-- | libdwfl/linux-pid-attach.c | 6 | ||||
-rw-r--r-- | libdwfl/relocate.c | 8 |
6 files changed, 26 insertions, 10 deletions
diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog index d107e78f..fedf65a4 100644 --- a/libdwfl/ChangeLog +++ b/libdwfl/ChangeLog | |||
@@ -1,3 +1,13 @@ | |||
1 | 2021-04-19 Martin Liska <mliska@suse.cz> | ||
2 | |||
3 | * dwfl_frame.c (dwfl_attach_state): Use startswith. | ||
4 | * dwfl_module_getdwarf.c (find_symtab): Likewise. | ||
5 | * linux-kernel-modules.c: Likewise. | ||
6 | * linux-pid-attach.c (linux_proc_pid_is_stopped): Likewise. | ||
7 | (dwfl_linux_proc_attach): Likewise. | ||
8 | * relocate.c (resolve_symbol): Likewise. | ||
9 | (relocate_section): Likewise. | ||
10 | |||
1 | 2021-02-01 Érico Nogueira <ericonr@disroot.org> | 11 | 2021-02-01 Érico Nogueira <ericonr@disroot.org> |
2 | 12 | ||
3 | * dwfl_error.c (strerror_r): Only use the GNU version when available. | 13 | * dwfl_error.c (strerror_r): Only use the GNU version when available. |
diff --git a/libdwfl/dwfl_frame.c b/libdwfl/dwfl_frame.c index 5bbf850e..77e0c5cb 100644 --- a/libdwfl/dwfl_frame.c +++ b/libdwfl/dwfl_frame.c | |||
@@ -30,6 +30,8 @@ | |||
30 | # include <config.h> | 30 | # include <config.h> |
31 | #endif | 31 | #endif |
32 | 32 | ||
33 | #include <system.h> | ||
34 | |||
33 | #include "libdwflP.h" | 35 | #include "libdwflP.h" |
34 | #include <unistd.h> | 36 | #include <unistd.h> |
35 | 37 | ||
@@ -172,7 +174,7 @@ dwfl_attach_state (Dwfl *dwfl, Elf *elf, pid_t pid, | |||
172 | is called from dwfl_linux_proc_attach with elf == NULL. | 174 | is called from dwfl_linux_proc_attach with elf == NULL. |
173 | __libdwfl_module_getebl will call __libdwfl_getelf which | 175 | __libdwfl_module_getebl will call __libdwfl_getelf which |
174 | will call the find_elf callback. */ | 176 | will call the find_elf callback. */ |
175 | if (strncmp (mod->name, "[vdso: ", 7) == 0 | 177 | if (startswith (mod->name, "[vdso: ") |
176 | || strcmp (strrchr (mod->name, ' ') ?: "", | 178 | || strcmp (strrchr (mod->name, ' ') ?: "", |
177 | " (deleted)") == 0) | 179 | " (deleted)") == 0) |
178 | continue; | 180 | continue; |
diff --git a/libdwfl/dwfl_module_getdwarf.c b/libdwfl/dwfl_module_getdwarf.c index 2f3dd0dd..6f076057 100644 --- a/libdwfl/dwfl_module_getdwarf.c +++ b/libdwfl/dwfl_module_getdwarf.c | |||
@@ -1162,7 +1162,7 @@ find_symtab (Dwfl_Module *mod) | |||
1162 | if (sname == NULL) | 1162 | if (sname == NULL) |
1163 | goto elferr; | 1163 | goto elferr; |
1164 | 1164 | ||
1165 | if (strncmp (sname, ".zdebug", strlen (".zdebug")) == 0) | 1165 | if (startswith (sname, ".zdebug")) |
1166 | /* Try to uncompress, but it might already have been, an error | 1166 | /* Try to uncompress, but it might already have been, an error |
1167 | might just indicate, already uncompressed. */ | 1167 | might just indicate, already uncompressed. */ |
1168 | elf_compress_gnu (symstrscn, 0, 0); | 1168 | elf_compress_gnu (symstrscn, 0, 0); |
@@ -1245,7 +1245,7 @@ find_symtab (Dwfl_Module *mod) | |||
1245 | if (sname == NULL) | 1245 | if (sname == NULL) |
1246 | goto elferr; | 1246 | goto elferr; |
1247 | 1247 | ||
1248 | if (strncmp (sname, ".zdebug", strlen (".zdebug")) == 0) | 1248 | if (startswith (sname, ".zdebug")) |
1249 | /* Try to uncompress, but it might already have been, an error | 1249 | /* Try to uncompress, but it might already have been, an error |
1250 | might just indicate, already uncompressed. */ | 1250 | might just indicate, already uncompressed. */ |
1251 | elf_compress_gnu (aux_strscn, 0, 0); | 1251 | elf_compress_gnu (aux_strscn, 0, 0); |
diff --git a/libdwfl/linux-kernel-modules.c b/libdwfl/linux-kernel-modules.c index 6edb27f2..c0f8dfa4 100644 --- a/libdwfl/linux-kernel-modules.c +++ b/libdwfl/linux-kernel-modules.c | |||
@@ -924,7 +924,7 @@ dwfl_linux_kernel_module_section_address | |||
924 | 924 | ||
925 | if (!strcmp (secname, ".modinfo") | 925 | if (!strcmp (secname, ".modinfo") |
926 | || !strcmp (secname, ".data.percpu") | 926 | || !strcmp (secname, ".data.percpu") |
927 | || !strncmp (secname, ".exit", 5)) | 927 | || startswith (secname, ".exit")) |
928 | { | 928 | { |
929 | *addr = (Dwarf_Addr) -1l; | 929 | *addr = (Dwarf_Addr) -1l; |
930 | return DWARF_CB_OK; | 930 | return DWARF_CB_OK; |
@@ -935,7 +935,7 @@ dwfl_linux_kernel_module_section_address | |||
935 | behavior, and this cruft leaks out into the /sys information. | 935 | behavior, and this cruft leaks out into the /sys information. |
936 | The file name for ".init*" may actually look like "_init*". */ | 936 | The file name for ".init*" may actually look like "_init*". */ |
937 | 937 | ||
938 | const bool is_init = !strncmp (secname, ".init", 5); | 938 | const bool is_init = startswith (secname, ".init"); |
939 | if (is_init) | 939 | if (is_init) |
940 | { | 940 | { |
941 | if (asprintf (&sysfile, SECADDRDIRFMT "_%s", | 941 | if (asprintf (&sysfile, SECADDRDIRFMT "_%s", |
diff --git a/libdwfl/linux-pid-attach.c b/libdwfl/linux-pid-attach.c index fdf5c9b1..cd534825 100644 --- a/libdwfl/linux-pid-attach.c +++ b/libdwfl/linux-pid-attach.c | |||
@@ -30,6 +30,8 @@ | |||
30 | # include <config.h> | 30 | # include <config.h> |
31 | #endif | 31 | #endif |
32 | 32 | ||
33 | #include <system.h> | ||
34 | |||
33 | #include "libelfP.h" | 35 | #include "libelfP.h" |
34 | #include "libdwflP.h" | 36 | #include "libdwflP.h" |
35 | #include <sys/types.h> | 37 | #include <sys/types.h> |
@@ -59,7 +61,7 @@ linux_proc_pid_is_stopped (pid_t pid) | |||
59 | 61 | ||
60 | have_state = false; | 62 | have_state = false; |
61 | while (fgets (buffer, sizeof (buffer), procfile) != NULL) | 63 | while (fgets (buffer, sizeof (buffer), procfile) != NULL) |
62 | if (strncmp (buffer, "State:", 6) == 0) | 64 | if (startswith (buffer, "State:")) |
63 | { | 65 | { |
64 | have_state = true; | 66 | have_state = true; |
65 | break; | 67 | break; |
@@ -407,7 +409,7 @@ dwfl_linux_proc_attach (Dwfl *dwfl, pid_t pid, bool assume_ptrace_stopped) | |||
407 | char *line = NULL; | 409 | char *line = NULL; |
408 | size_t linelen = 0; | 410 | size_t linelen = 0; |
409 | while (getline (&line, &linelen, procfile) >= 0) | 411 | while (getline (&line, &linelen, procfile) >= 0) |
410 | if (strncmp (line, "Tgid:", 5) == 0) | 412 | if (startswith (line, "Tgid:")) |
411 | { | 413 | { |
412 | errno = 0; | 414 | errno = 0; |
413 | char *endptr; | 415 | char *endptr; |
diff --git a/libdwfl/relocate.c b/libdwfl/relocate.c index 88b5211d..0497bd4f 100644 --- a/libdwfl/relocate.c +++ b/libdwfl/relocate.c | |||
@@ -30,6 +30,8 @@ | |||
30 | # include <config.h> | 30 | # include <config.h> |
31 | #endif | 31 | #endif |
32 | 32 | ||
33 | #include <system.h> | ||
34 | |||
33 | #include "libelfP.h" | 35 | #include "libelfP.h" |
34 | #include "libdwflP.h" | 36 | #include "libdwflP.h" |
35 | 37 | ||
@@ -237,7 +239,7 @@ resolve_symbol (Dwfl_Module *referer, struct reloc_symtab_cache *symtab, | |||
237 | return DWFL_E_LIBELF; | 239 | return DWFL_E_LIBELF; |
238 | 240 | ||
239 | /* If the section is already decompressed, that isn't an error. */ | 241 | /* If the section is already decompressed, that isn't an error. */ |
240 | if (strncmp (sname, ".zdebug", strlen (".zdebug")) == 0) | 242 | if (startswith (sname, ".zdebug")) |
241 | elf_compress_gnu (scn, 0, 0); | 243 | elf_compress_gnu (scn, 0, 0); |
242 | 244 | ||
243 | if ((shdr->sh_flags & SHF_COMPRESSED) != 0) | 245 | if ((shdr->sh_flags & SHF_COMPRESSED) != 0) |
@@ -518,7 +520,7 @@ relocate_section (Dwfl_Module *mod, Elf *relocated, const GElf_Ehdr *ehdr, | |||
518 | Nothing to do here. */ | 520 | Nothing to do here. */ |
519 | return DWFL_E_NOERROR; | 521 | return DWFL_E_NOERROR; |
520 | 522 | ||
521 | if (strncmp (tname, ".zdebug", strlen ("zdebug")) == 0) | 523 | if (startswith (tname, ".zdebug")) |
522 | elf_compress_gnu (tscn, 0, 0); | 524 | elf_compress_gnu (tscn, 0, 0); |
523 | 525 | ||
524 | if ((tshdr->sh_flags & SHF_COMPRESSED) != 0) | 526 | if ((tshdr->sh_flags & SHF_COMPRESSED) != 0) |
@@ -539,7 +541,7 @@ relocate_section (Dwfl_Module *mod, Elf *relocated, const GElf_Ehdr *ehdr, | |||
539 | if (sname == NULL) | 541 | if (sname == NULL) |
540 | return DWFL_E_LIBELF; | 542 | return DWFL_E_LIBELF; |
541 | 543 | ||
542 | if (strncmp (sname, ".zdebug", strlen ("zdebug")) == 0) | 544 | if (startswith (sname, ".zdebug")) |
543 | elf_compress_gnu (scn, 0, 0); | 545 | elf_compress_gnu (scn, 0, 0); |
544 | 546 | ||
545 | if ((shdr->sh_flags & SHF_COMPRESSED) != 0) | 547 | if ((shdr->sh_flags & SHF_COMPRESSED) != 0) |