Commit graph

106 commits

Author SHA1 Message Date
Undefine
97cc33ca47 Everywhere: Make the codebase more architecture aware 2022-07-27 21:46:42 +00:00
sin-ack
c8585b77d2 Everywhere: Replace single-char StringView op. arguments with chars
This prevents us from needing a sv suffix, and potentially reduces the
need to run generic code for a single character (as contains,
starts_with, ends_with etc. for a char will be just a length and
equality check).

No functional changes.
2022-07-12 23:11:35 +02:00
sin-ack
3f3f45580a Everywhere: Add sv suffix to strings relying on StringView(char const*)
Each of these strings would previously rely on StringView's char const*
constructor overload, which would call __builtin_strlen on the string.
Since we now have operator ""sv, we can replace these with much simpler
versions. This opens the door to being able to remove
StringView(char const*).

No functional changes.
2022-07-12 23:11:35 +02:00
Marcus Nilsson
da8eea69e4 LibDebug: Make sure current_breakpoint has value before usage
Previously this caused a crash when no breakpoint was active since we
tried to get value().address before the has_value() check.
2022-07-03 21:54:46 +00:00
Idan Horowitz
086969277e Everywhere: Run clang-format 2022-04-01 21:24:45 +01:00
Lenny Maiorani
d5d795b55e Libraries: Use default constructors/destructors in LibDebug
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#cother-other-default-operation-rules

"The compiler is more likely to get the default semantics right and
you cannot implement these functions better than the compiler."
2022-03-10 18:04:26 -08:00
Ali Mohammad Pur
e0db9cb876 LibDebug+LibCoredump: Replace remaining reinterpret_casts and C casts
You misused your toys and I'm now taking them away, reflect on what you
did wrong for a bit.
2022-01-28 22:51:27 +00:00
Ali Mohammad Pur
da3c4e5df5 LibDebug+LibCoredump: Use ByteReader to do unaligned reads
The previous solution of "lol whats a UB" was not nice and tripped over
itself when it was run under UBSAN, fix this by doing explicit
byte-by-byte reads where needed.
2022-01-28 22:51:27 +00:00
Ali Mohammad Pur
6d64b13a1b LibDebug+Everywhere: Avoid void* -> FlatPtr -> void* dance
And limit the `void*` to the functions that interface the system (i.e.
ptrace wrappers).
This generally makes the code less riddled with casts.
2022-01-28 22:51:27 +00:00
mjz19910
10ec98dd38 Everywhere: Fix spelling mistakes 2022-01-07 15:44:42 +01:00
mjz19910
3102d8e160 Everywhere: Fix many spelling errors 2022-01-07 10:56:59 +01:00
Itamar
a02d8e5710 LibDebug: Add optional setup_child() callback to debugger
If set, this callback gets called right after fork() in the child
process.

It can be used by the caller if it wants to perform some logic in the
child process before it starts executing the debuggee program.
2021-12-22 02:14:32 -08:00
Daniel Bertalan
815f15f82c LibDebug: Handle DWARF 4 address ranges
The format of the address range section is different between DWARF
version 4 and version 5. This meant that we parsed programs compiled
with `-gdwarf-4` incorrectly.
2021-12-15 10:27:12 -08:00
Daniel Bertalan
7546295abe LibDebug: Fix truncation in ExtendedOpcodes::SetDiscriminator
The parameter of this operator is an unsigned LEB128 integer, so it can
be more than 1 byte in length. If we only read 1 byte, we might mess up
the offsets for the instructions following it.
2021-12-15 10:27:12 -08:00
Andreas Kling
58fb3ebf66 LibCore+AK: Move MappedFile from AK to LibCore
MappedFile is strictly a userspace thing, so it doesn't belong in AK
(which is supposed to be user/kernel agnostic.)
2021-11-23 11:33:36 +01:00
Itamar
94d68583fb HackStudio: Use ProcessInspector instead of DebugSession where possible 2021-11-20 21:22:24 +00:00
Itamar
7950f5cb51 LibDebug: Add ProcessInspector base class
ProcessInspector is an abstract base class for an object that can
inspect the address space of a process.

Concrete sub classes need to implement methods for peeking & poking
memory and walking the loaded libraries.

It is currently only implemented by DebugSession.
2021-11-20 21:22:24 +00:00
Andreas Kling
587f9af960 AK: Make JSON parser return ErrorOr<JsonValue> (instead of Optional)
Also add slightly richer parse errors now that we can include a string
literal with returned errors.

This will allow us to use TRY() when working with JSON data.
2021-11-17 00:21:10 +01:00
Andreas Kling
8b1108e485 Everywhere: Pass AK::StringView by value 2021-11-11 01:27:46 +01:00
Tim Schumacher
80cb44afae Everywhere: Move shared library checks into a common function
While we're at it, unify the various different conditions that are
scattered accross the codebase.
2021-11-10 14:42:49 +01:00
Daniel Bertalan
bb4bb3c2f4 LibDebug: Enable parsing libgcc_s.so
Now that our DWARF 5 support is nearly feature-complete, there is no
reason anymore to special-case this library, as we can process it just
fine.
2021-10-17 17:09:58 +01:00
Daniel Bertalan
a60d960420 LibDebug: Don't create compilation units for embedded resources
Our implementation (naively) assumes that there is a one-to-one
correspondence between compilation units and line programs, and that
their orders are identical. This is not the case for embedded resources,
as Clang only creates line programs for it, but not compilation units.

This mismatch caused an assertion failure, which made generating
backtraces for GUI applications impossible. This commit introduces a
hack that skips creating CompilationUnit objects for LinePrograms that
come from embedded resources.
2021-10-17 17:09:58 +01:00
Daniel Bertalan
622d408d82 LibDebug: Make use of the newly supported data forms
With this change, our DWARF 5 support is nearly feature-complete.
2021-10-17 17:09:58 +01:00
Daniel Bertalan
8278039105 LibDebug: Support DW_FORM_data16
Clang emits this form at all debug levels.
2021-10-17 17:09:58 +01:00
Daniel Bertalan
ac53569bd1 LibDebug: Support addrx*, strx* and rnglistx forms
These forms were introduced in DWARF5, and have a fair deal of
advantages over the more traditional encodings: they reduce the size of
the binary and the number of relocations.

GCC does not emit these with `-g1` by default, but Clang does at all
debug levels.
2021-10-17 17:09:58 +01:00
Daniel Bertalan
8e5b70a0ba LibDebug: Don't expose AttributeValue internals, use getters instead
This will be needed when we add `DW_FORM_strx*` and `DW_FORM_addrx*`
support, which requires us to fetch `DW_AT_str_offsets_base` and
`DW_AT_addr_base` attributes from the parent compilation unit. This
can't be done as we read the values, because it would create infinite
recursion (as we might try to parse the compilation unit's
`DW_FORM_strx*` encoded name before we get to the attribute). Having
getters ensures that we will perform lookups if they are needed.
2021-10-17 17:09:58 +01:00
Andreas Kling
6b2e4f896b LibDebug: Add missing break in AddressRanges::for_each_range() 2021-09-28 18:05:42 +02:00
Itamar
09153b8997 LibDebug: Use DW_AT_ranges to get address ranges of DIEs
Previously, we only supported DIEs with a contiguous address ranges and
ignored ones with a non-contiguous set of ranges.

We now check if a DIE has the DW_AT_ranges attribute, and if it does we
parse its range list.

This improves the quality of our backtraces - we previously missed many
inlined function calls because their DIEs had non-contigues address
ranges.
2021-09-28 16:54:39 +02:00
Itamar
26a96d315d LibDebug: Support parsing non-contiguous DWARF address ranges
This adds support for parsing DWARF "range lists", which are identified
by the DW_AT_ranges form.

They contain code addresses for DIEs whose location is not contiguous.
2021-09-28 16:54:39 +02:00
Itamar
2b04a86d4d LibDebug: Add Dwarf::CompilationUnit::base_address()
The base address of the compilation unit is used in some range lists
entry types.
2021-09-28 16:54:39 +02:00
Brian Gianforcaro
c5cdb6eb4c LibDebug: Dont copy an AbbreviationEntry every time we retrieve a value
These API's are used in a variety of ways when building the die cache.
Each AbbreviationEntry has vector and other members, so avoid copying
it at all costs.
2021-09-18 21:05:13 +02:00
Brian Gianforcaro
952441943f LibDebug: Avoid short lived allocations in DIE::for_each_child
This algorithm is both iterative and recursive, so allocating on every
recursion, or when iterating each child is extremely costly.

Instead allow the on stack DIE to be re-initialized so it can be reused.
2021-09-18 21:05:13 +02:00
Itamar
c78838c2d2 LibDebug: Use the first memory segment of a library as the ELF's base
When parsing the libraries of the debugee process, we previously
assumed that the region that's called `<library name>: .text` was also
the base of the ELF file.

However, since we started linking with `-z separate-code`, this is no
longer the case - our executables have a read-only segment before the
.text segment, and that segment is actually at the base of the ELF.

This broke inserting breakpoints with the debugger since they were
inserted at a wrong offset.

To fix that, we now use the address of the first segment in the memory
map for the ELF's base address (The memory map is sorted by address).
2021-09-10 13:57:34 +00:00
Andreas Kling
e40e91b9df LibDebug: Use HashMap::ensure() in DebugInfo::prepare_lines() 2021-09-04 20:30:56 +02:00
Daniel Bertalan
7396e4aedc LibDebug: Store 64-bit numbers in AttributeValue
This helps us avoid weird truncation issues and fixes a bug on Clang
builds where truncation while reading caused the DIE offsets following
large LEB128 numbers to be incorrect. This removes the need for the
separate `LongUnsignedNumber` type.
2021-08-08 10:55:36 +02:00
Daniel Bertalan
a59b9357e3 LibDebug: Keep track of 'prologue end'
This LineProgram instruction is emitted by Clang. Although we currently
have no use for it (it's mostly a debugger feature), we need to handle
this opcode, as otherwise CrashReporter wouldn't work.
2021-08-08 10:55:36 +02:00
Ali Mohammad Pur
c4437e19bd LibDebug+Everywhere: Make DebugInfo not own the ELF image
This is required to avoid copying the image where otherwise a reference
would be enough.
2021-08-06 01:14:03 +02:00
Gunnar Beutner
f87cc85cd3 LibDebug: Make single-stepping work for x86_64 2021-08-02 17:11:47 +02:00
Gunnar Beutner
db1c5c4830 LibELF+Utilities: Avoid truncating 64-bit values
This fixes displaying 64-bit addresses in readelf and also fixes
showing backtraces from core dumps on x86_64.
2021-07-22 08:57:01 +02:00
Ali Mohammad Pur
f364fcec5d LibRegex+Everywhere: Make LibRegex more unicode-aware
This commit makes LibRegex (mostly) capable of operating on any of
the three main string views:
- StringView for raw strings
- Utf8View for utf-8 encoded strings
- Utf32View for raw unicode strings

As a result, regexps with unicode strings should be able to properly
handle utf-8 and not stop in the middle of a code point.
A future commit will update LibJS to use the correct type of string
depending on the flags.
2021-07-18 21:10:55 +04:30
Gunnar Beutner
2c41e89d08 LibDebug: Implement symbolication for x86_64 2021-07-13 23:19:33 +02:00
Gunnar Beutner
567fa4b2f0 LibDebug: Fix spelling mistake 2021-07-13 23:19:33 +02:00
Daniel Bertalan
2db4709c0c Everywhere: Add braces to aggregate initializers
This fixes a couple of warnings emitted by Clang.
2021-07-08 10:11:00 +02:00
Daniel Bertalan
ca06fd658d Everywhere: Remove unused local variables and lambda captures 2021-07-08 10:11:00 +02:00
Max Wipfli
fc6d051dfd AK+Everywhere: Add and use static APIs for LexicalPath
The LexicalPath instance methods dirname(), basename(), title() and
extension() will be changed to return StringView const& in a further
commit. Due to this, users creating temporary LexicalPath objects just
to call one of those getters will recieve a StringView const& pointing
to a possible freed buffer.

To avoid this, static methods for those APIs have been added, which will
return a String by value to avoid those problems. All cases where
temporary LexicalPath objects have been used as described above haven
been changed to use the static APIs.
2021-06-30 11:13:54 +02:00
Gunnar Beutner
233ef26e4d Kernel+Userland: Add x86_64 registers to RegisterState/PtraceRegisters 2021-06-27 15:46:42 +02:00
Gunnar Beutner
c9a8dfa1bf Userland: Add more TODO()s for arch-specific code
This enables building more of the userspace applications for x86_64.
2021-06-24 09:27:13 +02:00
Itamar
3a4017b419 LibDebug: Convert LibDebug to east-const style 2021-06-19 14:51:18 +02:00
Itamar
a45b5ccd96 LibDebug: Add DebugInfo::get_source_position_with_inlines
This function returns the source position of a given address in the
program. If that address exists in an inline chain, then it also returns
the source positions that are in the chain.
2021-06-19 14:51:18 +02:00
Itamar
835efa1b6a LibDebug: Add DwarfInfo::get_cached_die_at_offset
This function returns a DIE object from the cache with the given offset
in the debug_info section.
2021-06-19 14:51:18 +02:00