Skip to content

Fix build failure on non-arm 32bit architectures #264

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: devel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/events.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,8 @@

#if defined PL_WIN
#define MEM_METRIC "%lld"
#elif defined __arm__
#define MEM_METRIC "%d"
#else
#define MEM_METRIC "%ld"
#define MEM_METRIC "%zd"
#endif
#define TIME_METRIC "%lu"
#define IDLE_METRIC "%d"
Expand Down
8 changes: 0 additions & 8 deletions src/linux/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,6 @@

#define PTHREAD_BUFFER_ITEMS 200

#if defined __arm__
#define ADDR_FMT "%x"
#define SIZE_FMT "%d"
#else
#define ADDR_FMT "%lx"
#define SIZE_FMT "%ld"
#endif

struct _proc_extra_info {
unsigned int page_size;
char statm_file[24];
Expand Down
2 changes: 1 addition & 1 deletion src/linux/proc/maps.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ proc_map_new(pid_t pid) {
ssize_t lower, upper;

int has_pathname = sscanf(
line, ADDR_FMT "-" ADDR_FMT " %s %*x %*x:%*x %*x %s\n", &lower,
line, "%zx-%zx %s %*x %*x:%*x %*x %s\n", &lower,
&upper, // Map bounds
perms, // Permissions
pathname // Binary path
Expand Down
4 changes: 2 additions & 2 deletions src/linux/py_proc.h
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ _py_proc__get_resident_memory(py_proc_t* self) {
int ret = 0;

ssize_t size, resident;
if (fscanf(statm, SIZE_FMT " " SIZE_FMT, &size, &resident) != 2)
if (fscanf(statm, "%zd %zd", &size, &resident) != 2)
ret = -1;

fclose(statm);
Expand Down Expand Up @@ -592,7 +592,7 @@ _py_proc__get_vm_maps(py_proc_t* self) {
// We print the maps instead so that we can resolve them later and use
// the CPU more efficiently to collect samples.
emit_metadata(
"map", ADDR_FMT "-" ADDR_FMT " %s", (addr_t)m->address, ((addr_t)m->address) + m->size, m->pathname
"map", "%zx-%zx %s", (addr_t)m->address, ((addr_t)m->address) + m->size, m->pathname
);
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/linux/py_thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.

#include <fcntl.h>
#include <inttypes.h>
#include <pthread.h>
#include <stdio.h>
#include <string.h>
Expand All @@ -38,7 +39,7 @@ _py_thread__is_idle(py_thread_t* self) {
char file_name[64];
char buffer[2048] = "";

sprintf(file_name, "/proc/%d/task/" SIZE_FMT "/stat", self->proc->pid, self->tid);
sprintf(file_name, "/proc/%d/task/%" PRIuPTR "/stat", self->proc->pid, self->tid);

cu_fd fd = open(file_name, O_RDONLY);
if (fd == -1) {
Expand Down
4 changes: 1 addition & 3 deletions src/logging.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,8 @@ logger_close(void) {

#if defined PL_WIN
#define MEM_VALUE "%llu"
#elif defined __arm__
#define MEM_VALUE "%u"
#else
#define MEM_VALUE "%lu"
#define MEM_VALUE "%zu"
#endif

void
Expand Down
6 changes: 2 additions & 4 deletions src/mojo.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,8 @@ enum {

#if defined PL_WIN
#define FORMAT_TID "%llx"
#elif defined __arm__
#define FORMAT_TID "%x"
#else
#define FORMAT_TID "%lx"
#define FORMAT_TID "%zx"
#endif

#if defined __arm__
Expand Down Expand Up @@ -104,7 +102,7 @@ mojo_integer(mojo_int_t integer, int sign) {

// We expect the least significant bits to be varied enough to provide a valid
// key. This way we can keep the size of references to a maximum of 4 bytes.
#define mojo_ref(integer) (mojo_integer(MOJO_INT32 & ((mojo_int_t)integer), 0))
#define mojo_ref(intorptr) (mojo_integer(MOJO_INT32 & ((mojo_int_t)(uintptr_t)intorptr), 0))

// Mojo events

Expand Down
8 changes: 1 addition & 7 deletions src/platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@
static size_t max_pid = 0;
#endif

#if defined __arm__
#define MAXPID_FORMAT "%d"
#else
#define MAXPID_FORMAT "%ld"
#endif

// ----------------------------------------------------------------------------
size_t
pid_max() {
Expand All @@ -24,7 +18,7 @@ pid_max() {
if (!isvalid(pid_max_file))
return 0;

int has_pid_max = (fscanf(pid_max_file, MAXPID_FORMAT, &max_pid) == 1);
int has_pid_max = (fscanf(pid_max_file, "%zu", &max_pid) == 1);
fclose(pid_max_file);
if (!has_pid_max)
return 0;
Expand Down
9 changes: 2 additions & 7 deletions src/py_proc_list.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#if defined PL_LINUX
#include <dirent.h>
#include <inttypes.h>

#include "linux/common.h"
#elif defined PL_MACOS
Expand Down Expand Up @@ -236,14 +237,8 @@ py_proc_list__update(py_proc_list_t* self) {
if (stat[0] == ' ')
stat++;

#ifdef __arm__
#define STAT_FMT "%c %d"
#else
#define STAT_FMT "%c %ld"
#endif

uintptr_t ppid;
if (sscanf(stat, STAT_FMT, (char*)buffer, &ppid) != 2) {
if (sscanf(stat, "%c %" SCNdPTR, (char*)buffer, &ppid) != 2) {
log_e("Failed to parse stat file for process %d", pid);
return;
}
Expand Down
11 changes: 3 additions & 8 deletions src/py_thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#define PY_THREAD_C

#include <inttypes.h>
#include <signal.h>
#include <string.h>
#include <sys/stat.h>
Expand Down Expand Up @@ -468,12 +469,6 @@ py_thread__is_interrupted(py_thread_t* self) {
// ----------------------------------------------------------------------------
#define MAX_STACK_FILE_SIZE 2048

#if defined __arm__
#define TID_FMT "%d"
#else
#define TID_FMT "%ld"
#endif

int
py_thread__save_kernel_stack(py_thread_t* self) {
char stack_path[48];
Expand All @@ -486,7 +481,7 @@ py_thread__save_kernel_stack(py_thread_t* self) {

sfree(_kstacks[self->tid]);

sprintf(stack_path, "/proc/%d/task/" TID_FMT "/stack", self->proc->pid, self->tid);
sprintf(stack_path, "/proc/%d/task/%" PRIuPTR "/stack", self->proc->pid, self->tid);
cu_fd fd = open(stack_path, O_RDONLY);
if (fd == -1) {
log_e("Failed to open %s", stack_path);
Expand Down Expand Up @@ -644,7 +639,7 @@ _py_thread__unwind_native_frame_stack(py_thread_t* self) {
key_dt filename_key = (key_dt)pc;
filename = lru_cache__maybe_hit(string_cache, filename_key);
if (!isvalid(filename)) {
sprintf(_native_buf, "native@" ADDR_FMT, pc);
sprintf(_native_buf, "native@%" PRIuPTR, pc);
filename = strdup(_native_buf);
lru_cache__store(string_cache, (key_dt)pc, filename);
if (pargs.binary) {
Expand Down
Loading