implement attach and launch
This commit is contained in:
26
include/libedbg/error.hpp
Normal file
26
include/libedbg/error.hpp
Normal file
@@ -0,0 +1,26 @@
|
||||
#ifndef LIBEDBG_INCLUDE_ERROR_H
|
||||
#define LIBEDBG_INCLUDE_ERROR_H
|
||||
|
||||
#include <stdexcept>
|
||||
#include <cstring>
|
||||
|
||||
namespace edbg {
|
||||
class error final : public std::runtime_error {
|
||||
public:
|
||||
[[noreturn]]
|
||||
static void send(const std::string &msg) {
|
||||
throw error(msg);
|
||||
}
|
||||
|
||||
[[noreturn]]
|
||||
static void send_errno(const std::string &pfx) {
|
||||
throw error(pfx + ": " + std::strerror(errno));
|
||||
}
|
||||
|
||||
private:
|
||||
explicit error(const std::string &msg) : std::runtime_error(msg) {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif //LIBEDBG_INCLUDE_ERROR_H
|
||||
@@ -1,8 +0,0 @@
|
||||
#ifndef LIBEDBG_INCLUDE_LIBEDBG_H
|
||||
#define LIBEDBG_INCLUDE_LIBEDBG_H
|
||||
|
||||
namespace edbg {
|
||||
void hello();
|
||||
}
|
||||
|
||||
#endif //LIBEDBG_INCLUDE_LIBEDBG_H
|
||||
55
include/libedbg/process.hpp
Normal file
55
include/libedbg/process.hpp
Normal file
@@ -0,0 +1,55 @@
|
||||
#ifndef LIBEDBG_INCLUDE_PROCESS_H
|
||||
#define LIBEDBG_INCLUDE_PROCESS_H
|
||||
|
||||
#include <filesystem>
|
||||
#include <memory>
|
||||
#include <sys/types.h>
|
||||
|
||||
namespace edbg {
|
||||
enum class process_state {
|
||||
stopped,
|
||||
running,
|
||||
exited,
|
||||
terminated
|
||||
};
|
||||
|
||||
struct stop_reason {
|
||||
stop_reason(int wait_status);
|
||||
|
||||
process_state reason;
|
||||
std::uint8_t info;
|
||||
};
|
||||
|
||||
class process {
|
||||
public:
|
||||
process() = delete;
|
||||
|
||||
process(const process &) = delete;
|
||||
|
||||
process &operator=(const process &) = delete;
|
||||
|
||||
~process();
|
||||
|
||||
static std::unique_ptr<process> launch(std::filesystem::path path);
|
||||
|
||||
static std::unique_ptr<process> attach(pid_t pid);
|
||||
|
||||
void resume();
|
||||
|
||||
stop_reason wait_on_signal();
|
||||
|
||||
[[nodiscard]] pid_t pid() const { return pid_; }
|
||||
[[nodiscard]] process_state state() const { return state_; }
|
||||
|
||||
private:
|
||||
process(pid_t pid, bool terminate_on_end)
|
||||
: pid_(pid), terminate_on_end_(terminate_on_end) {
|
||||
}
|
||||
|
||||
pid_t pid_ = 0;
|
||||
bool terminate_on_end_ = true;
|
||||
process_state state_ = process_state::stopped;
|
||||
};
|
||||
}
|
||||
|
||||
#endif //LIBEDBG_INCLUDE_PROCESS_H
|
||||
Reference in New Issue
Block a user