Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file LICENSE.rst or https://cmake.org/licensing for details.

cmake_minimum_required(VERSION 4.2.0)

# Reject any attempt to use a toolchain file. We must not use one because
# we could be downloading it here. If the CMAKE_TOOLCHAIN_FILE environment
# variable is set, the cache variable will have been initialized from it.
unset(CMAKE_TOOLCHAIN_FILE CACHE)
unset(ENV{CMAKE_TOOLCHAIN_FILE})

# We name the project and the target for the ExternalProject_Add() call
# to something that will highlight to the user what we are working on if
# something goes wrong and an error message is produced.

project(libelfin-populate NONE)


# Pass through things we've already detected in the main project to avoid
# paying the cost of redetecting them again in ExternalProject_Add()
set(GIT_EXECUTABLE [==[/opt/homebrew/bin/git]==])
set(Git_VERSION [==[2.52.0]==])
set_property(GLOBAL PROPERTY _CMAKE_FindGit_GIT_EXECUTABLE_VERSION
[==[/opt/homebrew/bin/git;2.52.0]==]
)


include(ExternalProject)
ExternalProject_Add(libelfin-populate
"UPDATE_DISCONNECTED" "False" "GIT_REPOSITORY" "https://github.com/plasma-umass/libelfin.git" "EXTERNALPROJECT_INTERNAL_ARGUMENT_SEPARATOR" "GIT_TAG" "8bd19d1e4bb19ec1046d44e1ac1b3bb72b91d0c5" "GIT_SHALLOW" "TRUE"
SOURCE_DIR "/Users/emery/git/coz-portage/_deps/libelfin-src"
BINARY_DIR "/Users/emery/git/coz-portage/_deps/libelfin-build"
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
USES_TERMINAL_DOWNLOAD YES
USES_TERMINAL_UPDATE YES
USES_TERMINAL_PATCH YES
)


14 changes: 0 additions & 14 deletions Makefile

This file was deleted.

1 change: 0 additions & 1 deletion dwarf/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
*.o
to_string.cc
libdwarf++.a
libdwarf++.so
libdwarf++.so.*
Expand Down
75 changes: 0 additions & 75 deletions dwarf/Makefile

This file was deleted.

41 changes: 36 additions & 5 deletions dwarf/abbrev.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,37 @@ resolve_type(DW_AT name, DW_FORM form)
case DW_FORM::ref_addr:
case DW_FORM::ref_sig8:
case DW_FORM::ref_udata:
case DW_FORM::ref_sup4:
case DW_FORM::ref_sup8:
return value::type::reference;

case DW_FORM::string:
case DW_FORM::strp:
case DW_FORM::line_strp:
case DW_FORM::strp_sup:
case DW_FORM::strx:
case DW_FORM::strx1:
case DW_FORM::strx2:
case DW_FORM::strx3:
case DW_FORM::strx4:
return value::type::string;

case DW_FORM::addrx:
case DW_FORM::addrx1:
case DW_FORM::addrx2:
case DW_FORM::addrx3:
case DW_FORM::addrx4:
return value::type::address;

case DW_FORM::implicit_const:
return value::type::constant;

case DW_FORM::loclistx:
return value::type::loclist;

case DW_FORM::rnglistx:
return value::type::rangelist;

case DW_FORM::indirect:
// There's nothing meaningful we can do
return value::type::invalid;
Expand Down Expand Up @@ -138,15 +163,18 @@ resolve_type(DW_AT name, DW_FORM form)
return value::type::invalid;

default:
throw format_error("DW_FORM_sec_offset not expected for attribute " +
to_string(name));
// DWARF 5 has many new attributes using sec_offset
// (str_offsets_base, addr_base, rnglists_base, loclists_base, etc.)
// Just treat them as invalid for now to allow skipping
return value::type::invalid;
}
}
throw format_error("unknown attribute form " + to_string(form));
}

attribute_spec::attribute_spec(DW_AT name, DW_FORM form)
: name(name), form(form), type(resolve_type(name, form))
attribute_spec::attribute_spec(DW_AT name, DW_FORM form, int64_t implicit_const)
: name(name), form(form), type(resolve_type(name, form)),
implicit_const(implicit_const)
{
}

Expand All @@ -167,7 +195,10 @@ abbrev_entry::read(cursor *cur)
DW_FORM form = (DW_FORM)cur->uleb128();
if (name == (DW_AT)0 && form == (DW_FORM)0)
break;
attributes.push_back(attribute_spec(name, form));
int64_t implicit_const = 0;
if (form == DW_FORM::implicit_const)
implicit_const = cur->sleb128();
attributes.push_back(attribute_spec(name, form, implicit_const));
}
attributes.shrink_to_fit();
return true;
Expand Down
26 changes: 25 additions & 1 deletion dwarf/cursor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ cursor::string(std::string &out)
size_t size;
const char *p = this->cstr(&size);
out.resize(size);
memmove(&out.front(), p, size);
if (size > 0) {
memmove(&out.front(), p, size);
}
}

const char *
Expand Down Expand Up @@ -123,6 +125,8 @@ cursor::skip_form(DW_FORM form)
case DW_FORM::sec_offset:
case DW_FORM::ref_addr:
case DW_FORM::strp:
case DW_FORM::line_strp:
case DW_FORM::strp_sup:
switch (sec->fmt) {
case format::dwarf32:
pos += 4;
Expand Down Expand Up @@ -156,29 +160,49 @@ cursor::skip_form(DW_FORM form)

// fixed-length forms
case DW_FORM::flag_present:
case DW_FORM::implicit_const:
break;
case DW_FORM::flag:
case DW_FORM::data1:
case DW_FORM::ref1:
case DW_FORM::strx1:
case DW_FORM::addrx1:
pos += 1;
break;
case DW_FORM::data2:
case DW_FORM::ref2:
case DW_FORM::strx2:
case DW_FORM::addrx2:
pos += 2;
break;
case DW_FORM::strx3:
case DW_FORM::addrx3:
pos += 3;
break;
case DW_FORM::data4:
case DW_FORM::ref4:
case DW_FORM::ref_sup4:
case DW_FORM::strx4:
case DW_FORM::addrx4:
pos += 4;
break;
case DW_FORM::data8:
case DW_FORM::ref_sig8:
case DW_FORM::ref_sup8:
pos += 8;
break;
case DW_FORM::data16:
pos += 16;
break;

// variable-length forms
case DW_FORM::sdata:
case DW_FORM::udata:
case DW_FORM::ref_udata:
case DW_FORM::strx:
case DW_FORM::addrx:
case DW_FORM::loclistx:
case DW_FORM::rnglistx:
while (pos < sec->end && (*(uint8_t*)pos & 0x80))
pos++;
pos++;
Expand Down
51 changes: 51 additions & 0 deletions dwarf/data.hh
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,27 @@ enum class DW_FORM
sec_offset = 0x17, // lineptr, loclistptr, macptr, rangelistptr
exprloc = 0x18, // exprloc
flag_present = 0x19, // flag

// DWARF 5
strx = 0x1a, // string index in .debug_str_offsets
addrx = 0x1b, // address index in .debug_addr
ref_sup4 = 0x1c, // reference
strp_sup = 0x1d, // string
data16 = 0x1e, // constant
line_strp = 0x1f, // string
ref_sig8 = 0x20, // reference
implicit_const = 0x21, // constant encoded in abbrev
loclistx = 0x22, // location list index
rnglistx = 0x23, // range list index
ref_sup8 = 0x24, // reference
strx1 = 0x25, // 1-byte string index
strx2 = 0x26, // 2-byte string index
strx3 = 0x27, // 3-byte string index
strx4 = 0x28, // 4-byte string index
addrx1 = 0x29, // 1-byte address index
addrx2 = 0x2a, // 2-byte address index
addrx3 = 0x2b, // 3-byte address index
addrx4 = 0x2c, // 4-byte address index
};

std::string
Expand Down Expand Up @@ -560,6 +580,37 @@ enum class DW_LNE
std::string
to_string(DW_LNE v);

// Line number content types (DWARF5 section 7.22 table 7.30)
enum class DW_LNCT
{
path = 0x01,
directory_index = 0x02,
timestamp = 0x03,
size = 0x04,
MD5 = 0x05,
lo_user = 0x2000,
hi_user = 0x3fff,
};

std::string
to_string(DW_LNCT v);

// Range list entry encodings (DWARF5 section 7.25)
enum class DW_RLE : ubyte
{
end_of_list = 0x00,
base_addressx = 0x01,
startx_endx = 0x02,
startx_length = 0x03,
offset_pair = 0x04,
base_address = 0x05,
start_end = 0x06,
start_length = 0x07,
};

std::string
to_string(DW_RLE v);

DWARFPP_END_NAMESPACE

#endif
4 changes: 2 additions & 2 deletions dwarf/die.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ die::operator[](DW_AT attr) const
int i = 0;
for (auto &a : abbrev->attributes) {
if (a.name == attr)
return value(cu, a.name, a.form, a.type, attrs[i]);
return value(cu, a, attrs[i]);
i++;
}
}
Expand Down Expand Up @@ -174,7 +174,7 @@ die::attributes() const
// custom iterator.
int i = 0;
for (auto &a : abbrev->attributes) {
res.push_back(make_pair(a.name, value(cu, a.name, a.form, a.type, attrs[i])));
res.push_back(make_pair(a.name, value(cu, a, attrs[i])));
i++;
}
return res;
Expand Down
Loading