这段代码发生了什么?从名称和上下文中可以找到机器上的核心数量,但它是如何工作的?什么都有点摆弄?
static int32
getproccount(void)
{
uintptr buf[16], t;
int32 r, cnt, i;
cnt = 0;
r = runtime·sched_getaffinity(0, sizeof(buf), buf);
if(r > 0)
for(i = 0; i < r/sizeof(buf[0]); i++) {
t = buf[i];
t = t - ((t >> 1) & 0x5555555555555555ULL);
t = (t & 0x3333333333333333ULL) + ((t >> 2) & 0x3333333333333333ULL);
cnt += (int32)((((t + (t >> 4)) & 0xF0F0F0F0F0F0F0FULL) * 0x101010101010101ULL) >> 56);
}
return cnt ? cnt : 1;
}
Run Code Online (Sandbox Code Playgroud)
注意:忽略·in runtime·sched_getaffinity,将该行视为一个任意库/系统调用,它执行名称和参数所暗示的操作.(在这种情况下,这个特定的呼叫来自 …
所以我有以下代码:
#include <stdio.h>
#define MAX(a,b) (a) > (b) ? a : b
int abs(int a)
{
if (a > 0)
return a;
else
return a*-1;
}
inline int avg(int a, int b)
{
return (a+b)/2;
}
int math_max(int a, int b)
{
return (avg(a,b)+abs(avg(a,b)-b));
}
int main(int argc, char** argv)
{
return 0;
}
Run Code Online (Sandbox Code Playgroud)
当我编译它时:gcc -g test.c -o test我得到:
/tmp/ccZbHEju.o: In function `math_max':
test.c:(.text+0x33): undefined reference to `avg'
test.c:(.text+0x44): undefined reference to `avg'
collect2: error: ld returned 1 …Run Code Online (Sandbox Code Playgroud)
我正在尝试调试一个共享库,其中有使用 gdb 的源代码和调试符号。
我没有实际使用此共享库的进程的调试符号或代码(我自己编译它,所以我可以拥有一切,但生成的二进制文件被剥离,以模拟我没有代码的情况)。
该进程打印我正在尝试调试的目标函数 foo 的地址,以测试 gdb 是否知道共享库中符号的正确位置。foo 存在于我的共享库中。我的打印方法是将以下行添加到使用我的共享库的二进制文件中:
printf("%p\n", foo)
Run Code Online (Sandbox Code Playgroud)
...并且为了增加复杂性,这是我正在远程调试的 Android 系统。
我正在尝试的场景如下:
达到目标:
root@phone:/proc/23806 # gdbserver --attach :5555 23806
Attached; pid = 23806
Listening on port 5555
Remote debugging from host 127.0.0.1
Run Code Online (Sandbox Code Playgroud)
在主机上:
[build@build-machine shared]$ /home/build/shared/prebuilts/gcc/linux-x86/arm/arm-eabi-4.7/bin/arm-eabi-gdb
GNU gdb (GDB) 7.3.1-gg2
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted …Run Code Online (Sandbox Code Playgroud)