Skip to content

Commit

Permalink
[Debugger] windows debugger and process drawable (#953)
Browse files Browse the repository at this point in the history
* Update assert.h

* stuff for `process-drawable` to work

* add windows code for debugger

* debugger attaches

* something works

* remove bad ideas

* `(:break)` works

* connection fixes

* fixes + update docs

* crates & `defskelgroup` macro

* clang

* update tests and a few types

* temp

* temp

* fix files

* game builds

* reverse TypeConsistency operation

* add eye stuff for merc art login

* add `(:sym-name)`

* oops

* add `--auto-dbg` option to gc args

* codacy

* improve robustness of dgo unpacker and objectfiledb reading

* `cavegeyserrock`

* hopefully fix linux

* windows FormatMessage weirdness?

* mutex fixes

* fix merge conflicts

Co-authored-by: ManDude <7569514+ManDude@users.noreply.github.com>
  • Loading branch information
water111 and ManDude authored Oct 31, 2021
1 parent 7c5edf8 commit 8846968
Show file tree
Hide file tree
Showing 222 changed files with 42,198 additions and 1,191 deletions.
350 changes: 330 additions & 20 deletions common/cross_os_debug/xdbg.cpp

Large diffs are not rendered by default.

18 changes: 12 additions & 6 deletions common/cross_os_debug/xdbg.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
#ifdef __linux
#include <sys/types.h>
#elif _WIN32
// todo - windows includes
#define NOMINMAX
#include <Windows.h>
#endif

namespace xdbg {
Expand All @@ -40,15 +41,16 @@ struct MemoryHandle {

#elif _WIN32
struct ThreadID {
// todo - whatever windows uses to identify a thread
DWORD pid = 0;
DWORD tid = 0;

std::string to_string() const;
ThreadID(const std::string& str);
ThreadID(); // todo - add id type here, like in linux version
ThreadID(DWORD pid, DWORD tid);
ThreadID() = default;
};

struct MemoryHandle {
int a;
};
struct MemoryHandle {};
#endif

/*!
Expand Down Expand Up @@ -86,8 +88,12 @@ struct SignalInfo {
ILLEGAL_INSTR, // bad instruction
UNKNOWN, // some other signal that is unsupported
DISAPPEARED, // process disappeared (maybe killed by the user)
NOTHING, // nothing of importance. Windows sends many irrelevant (to us) events
EXCEPTION, // some unhandled exception

} kind = UNKNOWN;

std::string msg;
};

// Functions
Expand Down
8 changes: 5 additions & 3 deletions common/util/assert.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@

#if defined NDEBUG && defined _WIN32

#define _OLD_NDEBUG NDEBUG
#pragma push_macro("NDEBUG")

#undef NDEBUG
#undef assert
#include <cassert>
#define NDEBUG _OLD_NDEBUG

#undef _OLD_NDEBUG
#pragma pop_macro("NDEBUG")

#else

#include <cassert>

#endif

#define ASSERT assert
6 changes: 5 additions & 1 deletion decompiler/ObjectFile/ObjectFileDB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,11 @@ ObjectFileDB::ObjectFileDB(const std::vector<std::string>& _dgos,

lg::info("-Loading {} DGOs...", _dgos.size());
for (auto& dgo : _dgos) {
get_objs_from_dgo(dgo, config);
try {
get_objs_from_dgo(dgo, config);
} catch (std::runtime_error& e) {
lg::warn("Error when reading DGOs: {}", e.what());
}
}

lg::info("-Loading {} plain object files...", object_files.size());
Expand Down
10 changes: 5 additions & 5 deletions decompiler/analysis/final_output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,8 @@ std::string write_from_top_level_form(Form* top_form,
if (!something_matched) {
auto debug_match_result = match(defun_debug_matcher, &f);
if (debug_match_result.matched) {
auto first_name = debug_match_result.maps.strings.at(0);
auto second_name = debug_match_result.maps.strings.at(2);
auto& first_name = debug_match_result.maps.strings.at(0);
auto& second_name = debug_match_result.maps.strings.at(2);
if (first_name == second_name) {
auto func = file.try_get_function_at_label(debug_match_result.maps.label.at(1));
if (func) {
Expand All @@ -400,7 +400,7 @@ std::string write_from_top_level_form(Form* top_form,
auto define_match_result = match(define_symbol_matcher, &f);
if (define_match_result.matched) {
something_matched = true;
auto sym_name = define_match_result.maps.strings.at(0);
auto& sym_name = define_match_result.maps.strings.at(0);
auto symbol_type = dts.lookup_symbol_type(sym_name);
result +=
fmt::format(";; definition for symbol {}, type {}\n", sym_name, symbol_type.print());
Expand All @@ -419,7 +419,7 @@ std::string write_from_top_level_form(Form* top_form,
define_perm_match_result.maps.strings.at(0) ==
define_perm_match_result.maps.strings.at(2)) {
something_matched = true;
auto sym_name = define_perm_match_result.maps.strings.at(0);
auto& sym_name = define_perm_match_result.maps.strings.at(0);
auto symbol_type = dts.lookup_symbol_type(sym_name);

result += fmt::format(";; definition (perm) for symbol {}, type {}\n", sym_name,
Expand Down Expand Up @@ -500,4 +500,4 @@ std::string write_from_top_level(const Function& top_level,

return write_from_top_level_form(top_form, dts, file, skip_functions, env);
}
} // namespace decompiler
} // namespace decompiler
Loading

0 comments on commit 8846968

Please sign in to comment.