[英]how to prevent some values from being optimized out in linux kernel debugging?
This is a code in linux (5.4.21)这是 linux (5.4.21) 中的代码
When I use a virtual machine and connect gdb to the linux process, I can use break points and follow code.当我使用虚拟机并将gdb连接到linux进程时,我可以使用断点并跟随代码。 For example, I set breakpoint on a function arm_smmu_device_probe.
例如,我在函数 arm_smmu_device_probe 上设置断点。 When I follow with 'next' command, I see some values, for example, 'smmu' or 'dev' below are shown to have been optimized out.
当我使用“next”命令时,我看到一些值,例如,下面的“smmu”或“dev”显示已被优化。 How can I make them not optimized out so that I can see them in gdb?
我怎样才能使它们不被优化,以便我可以在 gdb 中看到它们?
static int arm_smmu_device_probe(struct platform_device *pdev)
{
int irq, ret;
struct resource *res;
resource_size_t ioaddr;
struct arm_smmu_device *smmu;
struct device *dev = &pdev->dev;
bool bypass;
smmu = devm_kzalloc(dev, sizeof(*smmu), GFP_KERNEL);
if (!smmu) {
dev_err(dev, "failed to allocate arm_smmu_device\n");
return -ENOMEM;
}
smmu->dev = dev;
if (dev->of_node) {
ret = arm_smmu_device_dt_probe(pdev, smmu);
} else {
ret = arm_smmu_device_acpi_probe(pdev, smmu);
if (ret == -ENODEV)
return ret;
}
I tried chaning -O2 to -Og in the top Makefile but the kernel build fails then.我尝试在顶部 Makefile 中将 -O2 更改为 -Og,但内核构建失败。
Recently I found how to do this.最近我发现了如何做到这一点。 (from Is there a way to tell GCC not to optimise a particular piece of code?<\/a> , flolo's answer)
(来自
Is there a way to tell GCC not to optimize a specific piece of code?<\/a> ,弗洛洛的回答)
If you want a function aaa(...) not to be optimzed, you can do it like this.如果您希望函数 aaa(...) 不被优化,您可以这样做。
#pragma GCC push_options
#pragma GCC optimize ("O0")
aaa ( ... )
{
function body
}
#prgma GCC pop_options
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.