| 9 | #include <unistd.h> // for getpid |
| 10 | |
| 11 | void process_map_cmd_handler(int pid, bool ps_map_list_all) { |
| 12 | |
| 13 | if (!proc_is_running(pid)) { |
| 14 | frontend_mark_task_fail("No processes is running with pid %d\n", pid); |
| 15 | return; |
| 16 | } |
| 17 | char path_to_maps[200]; |
| 18 | snprintf(path_to_maps, 199, "/proc/%d/maps", pid); |
| 19 | // |
| 20 | std::vector<std::string> proc_maps_file = read_file(path_to_maps); |
| 21 | |
| 22 | size_t special_mapping_count = 0; |
| 23 | // |
| 24 | |
| 25 | for (size_t i = 0; i < proc_maps_file.size(); i++) { |
| 26 | |
| 27 | struct mem_segment m_seg = parse_proc_map_str(proc_maps_file[i]); |
| 28 | // by default only show special region |
| 29 | if (!m_seg.is_special_region && !ps_map_list_all) |
| 30 | continue; |
| 31 | frontend_print("%s", m_seg.get_displayable_str().c_str()); |
| 32 | // count special region |
| 33 | if (m_seg.is_special_region) |
| 34 | special_mapping_count++; |
| 35 | } |
| 36 | |
| 37 | frontend_print("------------------------------------\n"); |
| 38 | frontend_print("Found total of %zu mappings\n", proc_maps_file.size()); |
| 39 | frontend_print("With %zu special region mapping\n", special_mapping_count); |
| 40 | frontend_print("------------------------------------\n"); |
| 41 | } |
| 42 | |
| 43 | void process_is_running_handler(int pid) { |
| 44 | bool is_running = proc_is_running(pid); |
no test coverage detected