总线错误和分段错误之间的区别?是否会发生程序发出seg故障并第一次停止并且第二次发生总线错误并退出?
在Linux中的通用x86用户态应用程序上会导致SIGBUS(总线错误)的原因是什么?我在网上找到的所有讨论都是关于内存对齐错误,根据我的理解,它并不适用于x86.
(我的代码在Geode上运行,以防有任何相关的处理器特定怪癖.)
我将Xcode更新为新的稳定版10.2v。我试图建立我的项目,并且成功了。当我尝试归档项目(工作区)时,出现如下屏幕截图所示的错误:

到目前为止,我已经尝试过:
我在macOS High Sierra上.
$ uname -v
Darwin Kernel Version 17.2.0: Fri Sep 29 18:27:05 PDT 2017; root:xnu-4570.20.62~3/RELEASE_X86_64
Run Code Online (Sandbox Code Playgroud)
我有以下合成程序.
void nop1() {
for (;;);
}
void nop2() {
while (1);
}
void nop3() {
int i = 0;
while(1) {
i++;
}
}
void nop4() {
static int i = 0;
while(1) {
i++;
};
}
int main() {
nop1();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
编辑2:我现在已经在下面的例子中用clang明确编译了.
当我编译并运行以下C程序与clang -O2我得到总线错误时main()调用nop1(),nop2(),nop3()但不适合nop4().
$ ./a.out …Run Code Online (Sandbox Code Playgroud) 我在OS X服务器上有一个git存储库,以前工作正常.我能够添加文件,提交它们,并将内容提取到我的笔记本电脑.
现在,当我进入服务器并执行git commit或git status在存储库中时,我在命令行中看到的只是bus error.
git log 仍然可以正常工作,并给我通常的输出.
我猜的东西是错误与资源库,因为在同一服务器上其他回购git commit和git status做仍然可以工作.
我该如何调试/修复此问题?
更新:我在问题发生之前重新创建了我上次创建的目录.这让我再做git status一次!
git commit -a但是,在此之后直接运行会出现以下错误:
fatal: Unable to create '/path/to/repo/.git/index.lock': File exists.
If no other git process is currently running, this probably means a
git process crashed in this repository earlier. Make sure no other git
process is running and remove the file manually to continue.
Run Code Online (Sandbox Code Playgroud)
然后我手动删除了index.lock文件,现在问题解决了..
我不知道出了什么问题.有任何想法吗..?
我们在这里处理C. 我只是想到了这个想法,想知道是否有可能访问存储函数的内存中的点foo,并将函数的内容复制到内存中的另一个点.具体来说,我正在努力让以下工作:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
void foo(){
printf("Hello World");
}
int main(){
void (*bar)(void) = malloc(sizeof foo);
memcpy(&bar, &foo, sizeof foo);
bar();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
但运行它会导致总线错误:Bus error: 10.我试图将函数的内容复制foo到一个内存空间bar然后执行新创建的函数bar.
除了查看这样的事情是否可能之外,没有其他原因可以揭示C语言的复杂性.我没想到它有什么实际用途.
我正在寻找指导让这个工作,或以其他方式被告知,有理由,为什么这不起作用
编辑查看一些答案并了解读取,写入和可执行内存,我突然意识到可以通过写入可执行内存来在C中动态创建函数.
我认为这是第一次失败的召唤.我写了C已经有一段时间了,我不知所措.非常感谢.
#include <stdio.h>
#include <string.h>
int main(int argc, char **argv) {
char *str = "one|two|three";
char *tok = strtok(str, "|");
while (tok != NULL) {
printf("%s\n", tok);
tok = strtok(NULL, "|");
}
return 0;
}
Run Code Online (Sandbox Code Playgroud) 我的代码中出现总线错误.使用此代码我试图将数字转换为单词,但我知道我的逻辑存在缺陷.但在此之前,当我在mac中使用g ++编译并运行此代码时,我正在尝试使此代码按原样运行并且我收到总线错误.任何帮助,将不胜感激.
当我运行代码时,我得到以下输出.我有调试消息来跟踪错误发生的位置.
Enter a number:1234
main 1:numbers are:234
Function1: Number is 234
two
two hundred
34Function2: Number is 34
Function3: Number is 34
Bus error: 10
#include <iostream>
#include <string>
using namespace std;
char *convert_number(int);
char *tens[]={"","ten", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"};
char *words[]={"zero","one", "two", "three", "four", "five", "six", "seven", "eight", "nine","ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen", "eighteen","ninteen"};
char *place[]={"","hundred","thouands","million","billion","trillion"};
int main(int argc, char **argv)
{
int number,conv_num,places;
places=1;
char *string= new char[1000];
char *temp_string = new char[100];
cout<<"Enter a number:"; …Run Code Online (Sandbox Code Playgroud)