Page MenuHomeFreeBSD

D23501.id67869.diff
No OneTemporary

D23501.id67869.diff

Index: contrib/elftoolchain/addr2line/addr2line.c
===================================================================
--- contrib/elftoolchain/addr2line/addr2line.c
+++ contrib/elftoolchain/addr2line/addr2line.c
@@ -411,6 +411,99 @@
return (NULL);
}
+static int
+check_range(Dwarf_Debug dbg, Dwarf_Die die, Dwarf_Unsigned addr,
+ struct CU **cu)
+{
+ Dwarf_Error de;
+ Dwarf_Unsigned addr_base, lopc, hipc;
+ Dwarf_Off off, ranges_off;
+ Dwarf_Signed ranges_cnt;
+ Dwarf_Ranges *ranges;
+ int i, ret;
+ bool in_range;
+
+ addr_base = 0;
+ ranges = NULL;
+ ranges_cnt = 0;
+ in_range = false;
+
+ ret = dwarf_attrval_unsigned(die, DW_AT_ranges, &ranges_off, &de);
+ if (ret == DW_DLV_NO_ENTRY) {
+ if (dwarf_attrval_unsigned(die, DW_AT_low_pc, &lopc, &de) ==
+ DW_DLV_OK) {
+ if (lopc == curlopc)
+ return (DW_DLV_ERROR);
+ if (dwarf_attrval_unsigned(die, DW_AT_high_pc, &hipc,
+ &de) == DW_DLV_OK) {
+ /*
+ * Check if the address falls into the PC
+ * range of this CU.
+ */
+ if (handle_high_pc(die, lopc, &hipc) !=
+ DW_DLV_OK)
+ return (DW_DLV_ERROR);
+ } else {
+ /* Assume ~0ULL if DW_AT_high_pc not present */
+ hipc = ~0ULL;
+ }
+
+ if (dwarf_dieoffset(die, &off, &de) != DW_DLV_OK) {
+ warnx("dwarf_dieoffset failed: %s",
+ dwarf_errmsg(de));
+ return (DW_DLV_ERROR);
+ }
+
+ if (addr >= lopc && addr < hipc) {
+ in_range = true;
+ }
+ }
+ } else if (ret == (DW_DLV_OK)) {
+ ret = dwarf_get_ranges(dbg, ranges_off, &ranges,
+ &ranges_cnt, NULL, &de);
+ if (ret != DW_DLV_OK)
+ return (ret);
+
+ if (!ranges || ranges_cnt <= 0)
+ return (DW_DLV_ERROR);
+
+ for (i = 0; i < ranges_cnt; i++) {
+ if (ranges[i].dwr_type == DW_RANGES_END)
+ return (DW_DLV_NO_ENTRY);
+
+ if (ranges[i].dwr_type ==
+ DW_RANGES_ADDRESS_SELECTION) {
+ addr_base = ranges[i].dwr_addr2;
+ continue;
+ }
+
+ /* DW_RANGES_ENTRY */
+ lopc = ranges[i].dwr_addr1 + addr_base;
+ hipc = ranges[i].dwr_addr2 + addr_base;
+
+ if (addr >= lopc && addr < hipc){
+ in_range = true;
+ }
+ }
+ } else {
+ return (DW_DLV_ERROR);
+ }
+
+ if (in_range) {
+ if ((*cu = calloc(1, sizeof(struct CU))) == NULL)
+ err(EXIT_FAILURE, "calloc");
+ (*cu)->lopc = lopc;
+ (*cu)->hipc = hipc;
+ (*cu)->die = die;
+ STAILQ_INIT(&(*cu)->funclist);
+ RB_INSERT(cutree, &cuhead, *cu);
+ curlopc = lopc;
+ return (DW_DLV_OK);
+ } else {
+ return (DW_DLV_NO_ENTRY);
+ }
+}
+
static void
translate(Dwarf_Debug dbg, Elf *e, const char* addrstr)
{
@@ -418,10 +511,9 @@
Dwarf_Line *lbuf;
Dwarf_Error de;
Dwarf_Half tag;
- Dwarf_Unsigned lopc, hipc, addr, lineno, plineno;
+ Dwarf_Unsigned addr, lineno, plineno;
Dwarf_Signed lcount;
Dwarf_Addr lineaddr, plineaddr;
- Dwarf_Off off;
struct CU *cu;
struct Func *f;
const char *funcname;
@@ -477,44 +569,11 @@
warnx("could not find DW_TAG_compile_unit die");
goto next_cu;
}
- if (dwarf_attrval_unsigned(die, DW_AT_low_pc, &lopc, &de) ==
- DW_DLV_OK) {
- if (lopc == curlopc)
- goto out;
- if (dwarf_attrval_unsigned(die, DW_AT_high_pc, &hipc,
- &de) == DW_DLV_OK) {
- /*
- * Check if the address falls into the PC
- * range of this CU.
- */
- if (handle_high_pc(die, lopc, &hipc) !=
- DW_DLV_OK)
- goto out;
- } else {
- /* Assume ~0ULL if DW_AT_high_pc not present */
- hipc = ~0ULL;
- }
-
- if (dwarf_dieoffset(die, &off, &de) != DW_DLV_OK) {
- warnx("dwarf_dieoffset failed: %s",
- dwarf_errmsg(de));
- goto out;
- }
-
- if (addr >= lopc && addr < hipc) {
- if ((cu = calloc(1, sizeof(*cu))) == NULL)
- err(EXIT_FAILURE, "calloc");
- cu->off = off;
- cu->lopc = lopc;
- cu->hipc = hipc;
- cu->die = die;
- STAILQ_INIT(&cu->funclist);
- RB_INSERT(cutree, &cuhead, cu);
-
- curlopc = lopc;
- break;
- }
- }
+ ret = check_range(dbg, die, addr, &cu);
+ if (ret == DW_DLV_OK)
+ break;
+ if (ret == DW_DLV_ERROR)
+ goto out;
next_cu:
if (die != NULL) {
dwarf_dealloc(dbg, die, DW_DLA_DIE);
Index: contrib/elftoolchain/elfcopy/main.c
===================================================================
--- contrib/elftoolchain/elfcopy/main.c
+++ contrib/elftoolchain/elfcopy/main.c
@@ -1390,6 +1390,7 @@
ecp->oec = elftc_bfd_target_class(tgt);
ecp->oed = elftc_bfd_target_byteorder(tgt);
ecp->oem = elftc_bfd_target_machine(tgt);
+ ecp->abi = elftc_bfd_target_osabi(tgt);
}
if (ecp->otf == ETF_EFI || ecp->otf == ETF_PE)
ecp->oem = elftc_bfd_target_machine(tgt);
Index: contrib/elftoolchain/libelftc/elftc.3
===================================================================
--- contrib/elftoolchain/libelftc/elftc.3
+++ contrib/elftoolchain/libelftc/elftc.3
@@ -57,6 +57,8 @@
Query the object format for a binary object descriptor.
.It Fn elftc_bfd_target_machine
Query the target machine for a binary object descriptor.
+.It Fn elftc_bfd_target_osabi
+Query the target osabi for a binary object descriptor.
.El
.It "C++ support"
.Bl -tag -compact -width indent
Index: contrib/elftoolchain/libelftc/elftc_bfd_find_target.3
===================================================================
--- contrib/elftoolchain/libelftc/elftc_bfd_find_target.3
+++ contrib/elftoolchain/libelftc/elftc_bfd_find_target.3
@@ -48,6 +48,8 @@
.Fn elftc_bfd_target_flavor "Elftc_Bfd_Target *target"
.Ft "unsigned int"
.Fn elftc_bfd_target_machine "Elftc_Bfd_Target *target"
+.Ft "unsigned int"
+.Fn elftc_bfd_target_osabi "Elftc_Bfd_Target *target"
.Sh DESCRIPTION
Function
.Fn elftc_bfd_find_target
Index: contrib/elftoolchain/libelftc/elftc_bfdtarget.c
===================================================================
--- contrib/elftoolchain/libelftc/elftc_bfdtarget.c
+++ contrib/elftoolchain/libelftc/elftc_bfdtarget.c
@@ -71,3 +71,10 @@
return (tgt->bt_machine);
}
+
+unsigned int
+elftc_bfd_target_osabi(Elftc_Bfd_Target *tgt)
+{
+
+ return (tgt->bt_osabi);
+}
Index: contrib/elftoolchain/libelftc/libelftc.h
===================================================================
--- contrib/elftoolchain/libelftc/libelftc.h
+++ contrib/elftoolchain/libelftc/libelftc.h
@@ -72,6 +72,7 @@
unsigned int elftc_bfd_target_byteorder(Elftc_Bfd_Target *_tgt);
unsigned int elftc_bfd_target_class(Elftc_Bfd_Target *_tgt);
unsigned int elftc_bfd_target_machine(Elftc_Bfd_Target *_tgt);
+unsigned int elftc_bfd_target_osabi(Elftc_Bfd_Target *_tgt);
int elftc_copyfile(int _srcfd, int _dstfd);
int elftc_demangle(const char *_mangledname, char *_buffer,
size_t _bufsize, unsigned int _flags);

File Metadata

Mime Type
text/plain
Expires
Sat, Aug 8, 3:46 AM (4 h, 52 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
36208569
Default Alt Text
D23501.id67869.diff (6 KB)

Event Timeline