mirror of
https://github.com/RPCS3/rpcs3.git
synced 2024-11-22 10:42:36 +01:00
GDB: Rework to_hex/hex_to functions
macOS defines uint64 as an alias of unsigned long long. Drop the length modifiers to resolve the warning on macOS: rpcs3/rpcs3/Emu/GDB.cpp:107:37: warning: format specifies type 'unsigned long *' but the argument has type 'u64 *' (aka 'unsigned long long *') [-Wformat] sscanf_s(val.c_str(), "%" HEX_U64, &result); ~~~~~~~~~~ ^~~~~~~ Also use std::from_chars to implement hex_to_{u8,u32,u64} instead of sscanf.
This commit is contained in:
parent
6837370a62
commit
900d7df40f
@ -27,8 +27,9 @@
|
|||||||
#include <sys/un.h> // sockaddr_un
|
#include <sys/un.h> // sockaddr_un
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <regex>
|
|
||||||
#include <charconv>
|
#include <charconv>
|
||||||
|
#include <regex>
|
||||||
|
#include <string_view>
|
||||||
|
|
||||||
extern bool ppu_breakpoint(u32 addr, bool is_adding);
|
extern bool ppu_breakpoint(u32 addr, bool is_adding);
|
||||||
|
|
||||||
@ -46,8 +47,6 @@ void set_nonblocking(int s)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#define sscanf_s sscanf
|
#define sscanf_s sscanf
|
||||||
#define HEX_U32 "x"
|
|
||||||
#define HEX_U64 "lx"
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
void set_nonblocking(int s)
|
void set_nonblocking(int s)
|
||||||
@ -56,8 +55,6 @@ void set_nonblocking(int s)
|
|||||||
ioctlsocket(s, FIONBIO, &mode);
|
ioctlsocket(s, FIONBIO, &mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define HEX_U32 "lx"
|
|
||||||
#define HEX_U64 "llx"
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct gdb_cmd
|
struct gdb_cmd
|
||||||
@ -79,34 +76,33 @@ bool check_errno_again()
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string u32_to_hex(u32 i) {
|
std::string u32_to_hex(u32 i) {
|
||||||
return fmt::format("%" HEX_U32, i);
|
return fmt::format("%x", i);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string u64_to_padded_hex(u64 value) {
|
std::string u64_to_padded_hex(u64 value) {
|
||||||
return fmt::format("%.16" HEX_U64, value);
|
return fmt::format("%.16x", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string u32_to_padded_hex(u32 value) {
|
std::string u32_to_padded_hex(u32 value) {
|
||||||
return fmt::format("%.8" HEX_U32, value);
|
return fmt::format("%.8x", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
u8 hex_to_u8(std::string val) {
|
template <typename T>
|
||||||
u8 result;
|
T hex_to(std::string_view val)
|
||||||
sscanf_s(val.c_str(), "%02hhX", &result);
|
{
|
||||||
|
T result;
|
||||||
|
auto [ptr, err] = std::from_chars(val.data(), val.data() + val.size(), result, 16);
|
||||||
|
if (err != std::errc())
|
||||||
|
{
|
||||||
|
fmt::throw_exception("Failed to read hex string: %s", std::make_error_code(err).message());
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 hex_to_u32(std::string val) {
|
constexpr auto& hex_to_u8 = hex_to<u8>;
|
||||||
u32 result;
|
constexpr auto& hex_to_u32 = hex_to<u32>;
|
||||||
sscanf_s(val.c_str(), "%" HEX_U32, &result);
|
constexpr auto& hex_to_u64 = hex_to<u64>;
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
u64 hex_to_u64(std::string val) {
|
|
||||||
u64 result;
|
|
||||||
sscanf_s(val.c_str(), "%" HEX_U64, &result);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
void gdb_thread::start_server()
|
void gdb_thread::start_server()
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user