diff --git a/quickstack2.cc b/quickstack2.cc index 6b916d0..ccc97c1 100644 --- a/quickstack2.cc +++ b/quickstack2.cc @@ -35,18 +35,18 @@ int* _attach_started = nullptr; stopper_symbol stopper[3] = { {"main", 0, 0}, {"start_thread", 0, 0}, {"do_sigwait", 0, 0}}; int num_stopper_symbol = 3; -string basic_libs[10] = {"ld-", - "libaio.", - "libc-", - "libm-", - "libdl-", - "libpthread-", - "librt-", - "libgcc_", - "libcrypt-", - "libnss_" - "libnsl_" - "libstdc++"}; +std::string basic_libs[10] = {"ld-", + "libaio.", + "libc-", + "libm-", + "libdl-", + "libpthread-", + "librt-", + "libgcc_", + "libcrypt-", + "libnss_" + "libnsl_" + "libstdc++"}; int num_basic_libs = 10; volatile sig_atomic_t shutdown_program = 0; int print_arg = 0; @@ -118,15 +118,15 @@ void print_stack(const char* format, ...) { va_end(args); } -static string dirname(const string& path) { +static std::string dirname(const std::string& path) { return path.substr(0, path.find_last_of('/')); } -static string basename(const string& path) { +static std::string basename(const std::string& path) { return path.substr(path.find_last_of('/') + 1); } -static bool startwith(const string& fullstring, const string& starting) { +static bool startwith(const std::string& fullstring, const std::string& starting) { if (fullstring.length() >= starting.length()) { if (!fullstring.compare(0, starting.length(), starting)) return true; @@ -136,7 +136,7 @@ static bool startwith(const string& fullstring, const string& starting) { return false; } -static bool endwith(const string& fullstring, const string& ending) { +static bool endwith(const std::string& fullstring, const std::string& ending) { if (fullstring.length() >= ending.length()) { return (0 == fullstring.compare(fullstring.length() - ending.length(), @@ -173,9 +173,9 @@ static int is_pid_stopped(int pid) { return retval; } -static bool match_debug_file(const string& name, const char* file) { - string ptr = file; - string ending = ".debug"; +static bool match_debug_file(const std::string& name, const char* file) { + std::string ptr = file; + std::string ending = ".debug"; if (name.empty() || ptr.empty()) return false; @@ -216,13 +216,13 @@ static int get_user_regs(int pid, user_regs_struct& regs) { } static char* find_debug_file(const char* stripped_file) { - string path; + std::string path; path = debug_dir; path += stripped_file; - string dirname1 = dirname(path); - string name = basename(path); + std::string dirname1 = dirname(path); + std::string name = basename(path); - string real_debug_file; + std::string real_debug_file; DIR* dp = opendir(dirname1.c_str()); if (dp) { struct dirent* dent; @@ -368,7 +368,7 @@ void bfd_handle::load_symbols(bool relative, ulong addr_begin) { symbol_ent e; e.addr = sinfo.value; - e.name = string(sinfo.name); + e.name = std::string(sinfo.name); st->symbols.push_back(e); } std::sort(st->symbols.begin(), st->symbols.end(), std::less()); @@ -444,13 +444,13 @@ static bool has_exec_permission(const char* filename) { return false; } -static void read_proc_map_ent(const string& line, +static void read_proc_map_ent(const std::string& line, proc_info& pinfo, symbol_table_map* stmap) { bool delete_marked = false; std::istringstream line_sin(line); - string tok; - vector tokens; + std::string tok; + std::vector tokens; while (line_sin >> tok) { tokens.push_back(tok); } @@ -459,7 +459,7 @@ static void read_proc_map_ent(const string& line, } else if (tokens.size() > 6 && startwith(tokens[6], "(deleted")) { delete_marked = true; } - const string& perms = tokens[1]; + const std::string& perms = tokens[1]; if (perms.size() == 5 && perms[3] != 'x') { return; } @@ -503,12 +503,12 @@ static void read_proc_map_ent(const string& line, } static void read_proc_maps(int pid, proc_info& pinfo, symbol_table_map* stmap) { - const string maps_file_path = "/proc/" + std::to_string(pid) + "/maps"; + const std::string maps_file_path = "/proc/" + std::to_string(pid) + "/maps"; std::ifstream maps_file(maps_file_path); if (!maps_file.is_open()) { return; } - string line; + std::string line; while (std::getline(maps_file, line)) { read_proc_map_ent(line, pinfo, stmap); } @@ -541,7 +541,7 @@ static const symbol_ent* find_symbol(const symbol_table* st, return &*j; } -static bool match_basic_lib(const string& path) { +static bool match_basic_lib(const std::string& path) { for (int i = 0; i < num_basic_libs; i++) { if (startwith(basename(path), basic_libs[i])) { return true; @@ -948,13 +948,13 @@ static int ptrace_detach_proc(int pid) { int get_tgid(int target_pid) { int tgid = -1; - const string status_file_path = + const std::string status_file_path = "/proc/" + std::to_string(target_pid) + "/status"; std::ifstream status_file(status_file_path); if (!status_file.is_open()) { return tgid; } - string line; + std::string line; while (std::getline(status_file, line)) { if (startwith(line, "Tgid")) { sscanf(line.c_str(), "Tgid:%d", &tgid); @@ -1036,7 +1036,7 @@ void print_trace_report(proc_info* pinfos, const thread_list& threads) { void attach_and_dump_all(const thread_list& threads, proc_info* pinfos, - vector* vals_sps, + std::vector* vals_sps, user_regs_struct* regs, bool* fails, bool lock_main) { @@ -1107,7 +1107,7 @@ void attach_and_dump_all(const thread_list& threads, void attach_and_dump_lock_all(const thread_list& threads, proc_info* pinfos, - vector* vals_sps, + std::vector* vals_sps, user_regs_struct* regs, bool* fails) { struct timeval tv_start, tv_end; @@ -1135,7 +1135,7 @@ void dump_stack(const thread_list& threads) { uint trace_length = 1000; symbol_table_map* stmap = new symbol_table_map(); proc_info* pinfos = new proc_info[threads.size()]; - vector* vals_sps = new vector[threads.size()]; + std::vector* vals_sps = new std::vector[threads.size()]; user_regs_struct* regs = new user_regs_struct[threads.size()]; bool* fails = new bool[threads.size()]; @@ -1176,10 +1176,10 @@ void dump_stack(const thread_list& threads) { if (single_line) { const size_t name_width = thread_names ? thread_info::max_name_len() + 2 : 0; - const string name_info = thread_names ? threads[i].name : ""; + const std::string name_info = thread_names ? threads[i].name : ""; print_stack("%d %-*s", threads[i].tid, name_width, name_info.c_str()); } else { - const string name_info = thread_names ? ", " + threads[i].name : ""; + const std::string name_info = thread_names ? ", " + threads[i].name : ""; print_stack("\nThread %ld (LWP %d)%s:\n", threads.size() - i, threads[i].tid, diff --git a/quickstack2.h b/quickstack2.h index 8924e95..3da4281 100644 --- a/quickstack2.h +++ b/quickstack2.h @@ -31,10 +31,6 @@ #include #include -using std::string; -using std::vector; -using std::map; - // From binutils/include/demangle.h #define DMGL_PARAMS (1 << 0) /* Include function args */ #define DMGL_ANSI (1 << 1) /* Include const, volatile, etc */ @@ -54,8 +50,8 @@ struct bfd_handle; struct symbol_ent { ulong addr; - string name; - symbol_ent(const ulong addr = 0, const string& name = "") + std::string name; + symbol_ent(const ulong addr = 0, const std::string& name = "") : addr(addr), name(name) {} }; @@ -64,7 +60,7 @@ inline bool operator<(const symbol_ent& lhs, const symbol_ent& rhs) { } struct symbol_table { - typedef vector symbols_type; + typedef std::vector symbols_type; symbols_type symbols; ulong text_vma; ulong text_size; @@ -145,7 +141,7 @@ struct symbol_table_map { void set(const std::string& path, symbol_table* st) { m[path] = st; } private: - typedef map m_type; + typedef std::map m_type; m_type m; private: @@ -157,7 +153,7 @@ struct proc_map_ent { ulong addr_begin; ulong addr_size; ulong offset; - string path; + std::string path; symbol_table* stbl; bool relative : 1; bool is_vdso : 1; @@ -176,7 +172,7 @@ inline bool operator<(const proc_map_ent& lhs, const proc_map_ent& rhs) { } struct proc_info { - typedef vector maps_type; + typedef std::vector maps_type; maps_type maps; struct timeval tv_start; struct timeval tv_end; @@ -184,14 +180,14 @@ struct proc_info { }; typedef struct stopper_symbol { - string name; + std::string name; ulong addr_begin; ulong addr_end; } stopper_symbol; typedef struct thread_info { thread_info(const int tid) : tid(tid) { - const string file_path = "/proc/" + std::to_string(tid) + "/comm"; + const std::string file_path = "/proc/" + std::to_string(tid) + "/comm"; std::ifstream comm_file(file_path); if (comm_file.is_open()) { std::getline(comm_file, name); @@ -206,14 +202,14 @@ typedef struct thread_info { } int tid; - string name; + std::string name; } thread_info; inline bool operator<(const thread_info& lhs, const thread_info& rhs) { return lhs.tid < rhs.tid; } -typedef struct vector thread_list; +typedef struct std::vector thread_list; extern int target_pid; extern int debug_level;