Changeset View
Standalone View
source/lib/sysdep/os/linux/ldbg.cpp
/* Copyright (C) 2010 Wildfire Games. | /* Copyright (C) 2010-2019 Wildfire Games. | ||||
* | * | ||||
* Permission is hereby granted, free of charge, to any person obtaining | * Permission is hereby granted, free of charge, to any person obtaining | ||||
* a copy of this software and associated documentation files (the | * a copy of this software and associated documentation files (the | ||||
* "Software"), to deal in the Software without restriction, including | * "Software"), to deal in the Software without restriction, including | ||||
* without limitation the rights to use, copy, modify, merge, publish, | * without limitation the rights to use, copy, modify, merge, publish, | ||||
* distribute, sublicense, and/or sell copies of the Software, and to | * distribute, sublicense, and/or sell copies of the Software, and to | ||||
* permit persons to whom the Software is furnished to do so, subject to | * permit persons to whom the Software is furnished to do so, subject to | ||||
* the following conditions: | * the following conditions: | ||||
Show All 18 Lines | |||||
// and it's easy enough to get people to run in gdb if we want a proper backtrace. | // and it's easy enough to get people to run in gdb if we want a proper backtrace. | ||||
// So we now go with the simple approach of not using BFD. | // So we now go with the simple approach of not using BFD. | ||||
#include "precompiled.h" | #include "precompiled.h" | ||||
#include "lib/sysdep/sysdep.h" | #include "lib/sysdep/sysdep.h" | ||||
#include "lib/debug.h" | #include "lib/debug.h" | ||||
#include <sys/syscall.h> | |||||
#if OS_ANDROID | #if OS_ANDROID | ||||
// Android NDK doesn't support backtrace() | // Android NDK doesn't support backtrace() | ||||
// TODO: use unwind.h or similar? | // TODO: use unwind.h or similar? | ||||
void* debug_GetCaller(void* UNUSED(context), const wchar_t* UNUSED(lastFuncToSkip)) | void* debug_GetCaller(void* UNUSED(context), const wchar_t* UNUSED(lastFuncToSkip)) | ||||
{ | { | ||||
return NULL; | return NULL; | ||||
▲ Show 20 Lines • Show All 98 Lines • ▼ Show 20 Lines | Status debug_ResolveSymbol(void* ptr_of_interest, wchar_t* sym_name, wchar_t* file, int* line) | ||||
else | else | ||||
{ | { | ||||
return ERR::FAIL; | return ERR::FAIL; | ||||
} | } | ||||
} | } | ||||
#endif | #endif | ||||
void debug_SetThreadName(char const* UNUSED(name)) | void debug_SetThreadName(char const* name) | ||||
{ | { | ||||
// Currently unimplemented | char pathname[32]; | ||||
pid_t tid = syscall(SYS_gettid); | |||||
vladislavbelov: It's not a portable function in nonstandard GNU extensions. So it's not guaranteed to be… | |||||
Not Done Inline Actions|/proc/self/task//comm| = 21. On some platforms typeof(tid) = uint64_t, length of maximum possible id has 20 symbol length. It means that 32 isn't enough here. vladislavbelov: `|/proc/self/task//comm| = 21`. On some platforms `typeof(tid) = uint64_t`, length of maximum… | |||||
Not Done Inline ActionsOh, I wasn’t aware that pid_t could be 64-bit, I’ll fix that. linkmauve: Oh, I wasn’t aware that `pid_t` could be 64-bit, I’ll fix that. | |||||
Not Done Inline ActionsOut of curiosity, which platform is that? linkmauve: Out of curiosity, which platform is that? | |||||
Not Done Inline ActionsIn this case though, the %u four lines below would have to be changed too on this platform; is there a PRI* macro for pid_t? linkmauve: In this case though, the `%u` four lines below would have to be changed too on this platform… | |||||
Not Done Inline ActionsI don't know about these modifiers, I can suggest to use a uint64_t as a proper type for most possible cases or just use std::stringstream, which is safe and easier. vladislavbelov: I don't know about these modifiers, I can suggest to use a `uint64_t` as a proper type for most… | |||||
snprintf(pathname, 32, "/proc/self/task/%u/comm", tid); | |||||
FILE* comm = fopen(pathname, "w"); | |||||
std::string limited_name(name, 15); | |||||
Done Inline ActionsIt'd be good to attach a comment, what's going there. Why do we need to open some file and which limitations do/did we have here. Why didn't we use the posix*_np function. vladislavbelov: It'd be good to attach a comment, what's going there. Why do we need to open some file and… | |||||
Done Inline ActionsWe use const char* in its declaration, so we might fix it here. vladislavbelov: We use `const char*` in its declaration, so we might fix it here. | |||||
Done Inline ActionsIt works only since Linux 2.6.33, maybe we need a comment about that. vladislavbelov: It works only since Linux 2.6.33, maybe we need a comment about that. | |||||
fputs(limited_name.c_str(), comm); | |||||
fclose(comm); | |||||
Not Done Inline ActionsCan't we use TASK_COMM_LEN here? vladislavbelov: Can't we use `TASK_COMM_LEN` here? | |||||
Not Done Inline ActionsThis constant isn’t defined on my system, where do you get it from? linkmauve: This constant isn’t defined on my system, where do you get it from? | |||||
Not Done Inline ActionsI think I was wrong here, because I can't find that documentation page where I saw it. Maybe just use std::stringstream everywhere? Since it shouldn't be called often. vladislavbelov: I think I was wrong here, because I can't find that documentation page where I saw it. Maybe… | |||||
} | } |
It's not a portable function in nonstandard GNU extensions. So it's not guaranteed to be present.