当我编写一个要与 一起使用的库时LD_PRELOAD,如何调试它的__attribute__((__constructor__))功能?它们似乎总是在 GDB 停止进程之前运行。作为 MCVE,运行以下命令:
cat > preflight.c <<EOF
#include <stdio.h>
#include <stdlib.h>
__attribute__((__constructor__))
void preflight(void) {
puts("Exiting from preflight");
exit(42);
}
EOF
gcc -g -fPIC -shared preflight.c -o preflight.so
gdb /bin/true -ex 'set environment LD_PRELOAD ./preflight.so' \
-ex 'set breakpoint pending on' \
-ex 'break preflight' \
-ex 'starti'
Run Code Online (Sandbox Code Playgroud)
GDB 输出的末尾将如下所示:
Function "preflight" not defined.
Breakpoint 1 (preflight) pending.
Starting program: /usr/bin/true
Exiting from preflight
During startup program exited with code 42.
(gdb)
Run Code Online (Sandbox Code Playgroud)
观察到该preflight …
对于我的家庭作业,我被要求编写一个脚本来模拟容器内的气体粒子。
现在我已经完成了数学部分,到目前为止它是这样工作的:
1) 输入一个包含位置坐标和移动向量的初始列表 2) 然后创建一个转换列表,由所有 x 坐标和 y 坐标组成,每个都在一个单独的子列表中,供以后绘图 3) 然后运行一系列我写的函数在间隔后更新列表中的位置和向量 4) 再次转换列表 5) 等等
但是我根本不知道如何为这些设置动画?
我想我需要这样的东西:
1) 绘制一个圆形用作容器 + 初始粒子/位置 2) 保持圆形并更新列表 3) 绘制圆形并更新列表 4) 等等,以非常快的速度
假设我想创建一个数学库.我需要处理的载体在不同的维度,所以我想有每个维度中的一个类(又名Vector2,Vector3,Vector4...)
到现在为止还挺好.但它会导致严重的代码重复,因为Vector3主要是某些函数中Vector2使用的z属性.
所以我有个主意.代码复制是机器而不是人类的任务,所以我可以这样写:
在Vector.hpp中:
#ifndef VECTOR_HPP
#define VECTOR_HPP
#define VECTOR_DIM 2
#include "_Vector.hpp"
#define VECTOR_DIM 3
#include "_Vector.hpp"
#define VECTOR_DIM 4
#include "_Vector.hpp"
#undef VECTOR_DIM
#endif
Run Code Online (Sandbox Code Playgroud)
在_Vector.hpp中:
// This header was not protected from multiple inclusions on purpose
#define VECTOR_NAME Vector ## VECTOR_DIM
class VECTOR_NAME
{
public:
// Some methods here ...
float x;
float y;
#if VECTOR_DIM >= 3
float z;
#endif
#if VECTOR_DIM >= 4
float …Run Code Online (Sandbox Code Playgroud) 考虑以下两个C程序:
#include <signal.h>
int main(void) {
raise(SIGTERM);
}
Run Code Online (Sandbox Code Playgroud)
int main(void) {
return 143;
}
Run Code Online (Sandbox Code Playgroud)
如果我运行任何一个,则$?bash中的值将为143。但是,通过waitsyscall可以区分它们:
wait4(-1, [{WIFSIGNALED(s) && WTERMSIG(s) == SIGTERM}], 0, NULL) = 11148
wait4(-1, [{WIFEXITED(s) && WEXITSTATUS(s) == 143}], 0, NULL) = 11214
Run Code Online (Sandbox Code Playgroud)
bash显然使用了这一知识,因为第一个导致将结果Terminated打印到终端上(奇怪的是,即使我将stdout和stderr都重定向到其他地方,也会发生这种情况),而第二个则没有。如何区分这两种情况与bash脚本?
我很难理解为什么类可以具有自身的不完整类型静态成员。
例如在下面的代码中。为什么允许在类A内拥有自身的不完整类型静态成员,但是当类类型B的全局静态变量是不完整类型时却出现错误?
class B {
public:
B(int a) {
}
};
static B test2; //error
class A {
public:
static A test; //accepted
A(int d) {
}
};
Run Code Online (Sandbox Code Playgroud)
有人可以向我解释在后台给全局静态变量带来错误的原因是什么,为什么A类内部的静态变量会被接受?
step :: [Int] -> String -> [Int]
step (x:y:ys) "*" = (x*y):ys
step (x:y:ys) "+" = (x + y):ys
step (x:y:ys) "-" = (y - x):ys
step xs numString = read numString : xs
Run Code Online (Sandbox Code Playgroud)
我正在从http://learnyouahaskell.com/functionally-solving-problems扩展我的知识
,我想尝试使用Maybe. 谁能给我一些关于定义以下函数的提示或任何有用的关键字(如果我的想法是正确的)?我想Just sts在我成功输入值Nothing时返回,而当我没有输入时。不知道我的概念是否正确,有人纠正我。
step2:: [Int] -> String -> Maybe [Int]
Run Code Online (Sandbox Code Playgroud) 最近,我听说 clang 有了一个新功能,_ExtInt. 我知道它可以让你指定一个整数的大小(奇数或什至像 13 位整数),但你如何使用它?
考虑这个 C 代码:
void foo(char *);
void bar(void) {
foo("");
}
Run Code Online (Sandbox Code Playgroud)
-pedantic -Wall -Wextra当我使用 GCC 或 Clang 或Clang编译该文件时-Weverything,它会编译而不会给出任何相关警告。如果我添加-Wwrite-strings,那么 GCC 会给我这个:
<source>:4:9: warning: passing argument 1 of 'foo' discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
4 | foo("");
| ^~
<source>:1:10: note: expected 'char *' but argument is of type 'const char *'
1 | void foo(char *);
| ^~~~~~
Run Code Online (Sandbox Code Playgroud)
clang 给了我这个:
<source>:4:9: warning: passing 'const char [1]' to parameter of type 'char *' discards …Run Code Online (Sandbox Code Playgroud) 我想写一个函数来读取Int没有do符号的。它有效(见下文),但我想知道它周围的位是否readMaybe可以以无点形式编写(或以其他方式清理一下)?
main :: IO ()
main = getLine >>= (\x -> return $ (readMaybe x :: Maybe Int)) >>= print
Run Code Online (Sandbox Code Playgroud) 我正在尝试编写一个程序,该程序可以在读取命令行参数后屏蔽它们。我知道它存储在 PEB 中,因此我尝试使用“如何使用汇编程序(x64 OS)获取进程环境块(PEB)地址?”的答案。通过 Sirmabus获取并在那里进行修改。这是一个执行此操作的最小程序:
\n#include <wchar.h>\n#include <windows.h>\n#include <winnt.h>\n#include <winternl.h>\n\n// Thread Environment Block (TEB)\n#if defined(_M_X64) // x64\nPTEB tebPtr = reinterpret_cast<PTEB>(__readgsqword(reinterpret_cast<DWORD_PTR>(&static_cast<NT_TIB*>(nullptr)->Self)));\n#else // x86\nPTEB tebPtr = reinterpret_cast<PTEB>(__readfsdword(reinterpret_cast<DWORD_PTR>(&static_cast<NT_TIB*>(nullptr)->Self)));\n#endif\n\n// Process Environment Block (PEB)\nPPEB pebPtr = tebPtr->ProcessEnvironmentBlock;\n\nint main() {\n UNICODE_STRING *s = &pebPtr->ProcessParameters->CommandLine;\n wmemset(s->Buffer, \'x\', s->Length / sizeof *s->Buffer);\n getwchar();\n}\nRun Code Online (Sandbox Code Playgroud)\n我将其编译为 32 位和 64 位,并在 32 位和 64 位版本的 Windows 上进行了测试。我使用Process Explorer查找命令行,并使用此 PowerShell 命令通过 WMI 获取它:
\nGet-WmiObject Win32_Process -Filter "name = \'overwrite.exe\'" | Select-Object CommandLine\nRun Code Online (Sandbox Code Playgroud)\n我发现这在我测试过的每个组合中都有效,除了在 WOW64 …