導航:首頁 > 源碼編譯 > 編譯libthreaddb

編譯libthreaddb

發布時間:2022-12-31 14:42:30

❶ 高通deviceinfo在哪個目錄

Google提供android包含原始Android目標機代碼主機編譯工具、模擬環境載代碼包經解壓(Android2.2源碼包)源代碼第層目錄結構:
|-- Makefile
|-- bionic (bionic C庫)
|-- bootable (啟引導相關代碼)
|-- build (存放系統編譯規則及generic等基礎發包配置)

|-- cts (Android兼容性測試套件標准)
|-- dalvik (dalvik java虛擬機)
|-- development (應用程序發相關)
|-- external (android使用些源模組)
|-- frameworks (核框架——java及C++語言)
|-- hardware (主要保護硬解適配層HAL代碼)
|-- libcore
|-- ndk
|-- device
|-- out (編譯完代碼輸與目錄)
|-- packages (應用程序包)
|-- prebuilt (x86arm架構預編譯些資源)
|-- sdk (sdk及模擬器)
|-- system (文件系統庫、應用及組件——C語言)
`-- vendor (廠商定製代碼)

bionic 目錄

|-- libc (C庫)
| |-- arch-arm (ARM架構包含系統調用匯編實現)
| |-- arch-x86 (x86架構包含系統調用匯編實現)
| |-- bionic (由C實現功能架構關)
| |-- docs (文檔)
| |-- include (文件)
| |-- inet
| |-- kernel (linux內核些文件)
| |-- netbsd (netbsd系統相關具體作用明)
| |-- private (些私文件)
| |-- stdio (stdio實現)
| |-- stdlib (stdlib實現)
| |-- string (string函數實現)
| |-- tools (幾工具)
| |-- tzcode (區相關代碼)
| |-- unistd (unistd實現)
| `-- zoneinfo (區信息)
|-- libdl (libdl實現dl態鏈接提供訪問態鏈接庫功能)
|-- libm (libm數庫實現)
| |-- alpha (apaha架構)
| |-- amd64 (amd64架構)
| |-- arm (arm架構)
| |-- bsdsrc (bsd源碼)
| |-- i386 (i386架構)
| |-- i387 (i387架構)
| |-- ia64 (ia64架構)
| |-- include (文件)
| |-- man (數函數綴名.3些freeBSD庫文件)
| |-- powerpc (powerpc架構)
| |-- sparc64 (sparc64架構)
| `-- src (源代碼)
|-- libstdc++ (libstdc++ C++實現庫)
| |-- include (文件)
| `-- src (源碼)
|-- libthread_db (線程程序調試器庫)
| `-- include (文件)
`-- linker (態鏈接器)
`-- arch (支持armx86兩種架構)

bootable 目錄

|-- bootloader (適合各種bootloader通用代碼)
| `-- legacy (估計能直接使用參考)
| |-- arch_armv6 (V6架構幾簡單匯編文件)
| |-- arch_msm7k (高通7k處理器架構幾基本驅)
| |-- include (通用文件高通7k架構文件)
| |-- libboot (啟庫都寫簡單)
| |-- libc (些用c函數)
| |-- nandwrite (nandwirte函數實現)
| `-- usbloader (usbloader實現)
|-- diskinstaller (android鏡像打包器x86產iso)
`-- recovery (系統恢復相關)
|-- edify (升級腳本使用edify腳本語言)
|-- etc (init.rc恢復腳本)
|-- minui (簡單UI)
|-- minzip (簡單壓縮工具)
|-- mttils (mtd工具)
|-- res (資源)
| `-- images (些圖片)
|-- tools (工具)
| `-- ota (OTA Over The Air Updates升級工具)
`-- updater (升級器)

build目錄

|-- core (核編譯規則)
|-- history (歷史記錄)
|-- libs
| `-- host (主機端庫android cp功能替換)
|-- target (目標機編譯象)
| |-- board (發平台)
| | |-- emulator (模擬器)
| | |-- generic (通用)
| | |-- idea6410 (自添加)
| | `-- sim (簡單)
| `-- proct (發平台應編譯規則)
| `-- security (密鑰相關)
`-- tools (編譯主機使用工具及腳本)
|-- acp (Android "acp" Command)
|-- apicheck (api檢查工具)
|-- applypatch (補丁工具)
|-- apriori (預鏈接工具)
|-- atree (tree工具)
|-- bin2asm (bin轉換asm工具)
|-- check_prereq (檢查編譯間戳工具)
|-- dexpreopt (模擬器相關工具具體功能明)
|-- droiddoc (作用明java語言網說JDK5關)
|-- fs_config (This program takes a list of files and directories)
|-- fs_get_stats (獲取文件系統狀態)
|-- iself (判斷否ELF格式)
|-- isprelinked (判斷否prelinked)
|-- kcm (按鍵相關)
|-- lsd (List symbol dependencies)
|-- releasetools (鏡像工具及腳本)
|-- rgb2565 (rgb轉換565)
|-- signapk (apk簽名工具)
|-- soslim (strip工具)
`-- zipalign (zip archive alignment tool)

dalvik目錄 dalvik虛擬機
.
|-- dalvikvm (main.c目錄)
|-- dexmp (dex反匯編)
|-- dexlist (List all methods in all concrete classes in a DEX file.)
|-- dexopt (預驗證與優化)
|-- docs (文檔)
|-- dvz (zygote相關命令
|-- dx (dx工具java轉換dex)
|-- hit (java語言寫)
|-- libcore (核庫)
|-- libcore-disabled (禁用庫)
|-- libdex (dex庫)
|-- libnativehelper (Support functions for Android's class libraries)
|-- tests (測試代碼)
|-- tools (工具)
`-- vm (虛擬機實現)

development 目錄 (發者需要些常式及工具)
|-- apps (些核應用程序)
| |-- BluetoothDebug (藍牙調試程序)
| |-- CustomLocale (自定義區域設置)
| |-- Development (發)
| |-- Fallback (語言相關程序)
| |-- FontLab (字型檔)
| |-- GestureBuilder (手勢作)
| |-- NinePatchLab ()
| |-- OBJViewer (OBJ查看器)
| |-- SdkSetup (SDK安裝器)
| |-- SpareParts (高級設置)
| |-- Term (遠程登錄)
| `-- launchperf ()
|-- build (編譯腳本模板)
|-- cmds (monkey工具)
|-- data (配置數據)
|-- docs (文檔)
|-- host (主機端USB驅等)
|-- ide (集發環境)
|-- ndk (本發套件——c語言發套件)
|-- pdk (Plug Development Kit)
|-- samples (演示程序)
| |-- AliasActivity ()
| |-- ApiDemos (API演示程序)
| |-- BluetoothChat (藍牙聊)
| |-- BrowserPlugin (瀏覽器插件)
| |-- BusinessCard (商業卡)
| |-- Compass (指南針)
| |-- ContactManager (聯系管理器)
| |-- CubeLiveWall** (態壁紙簡單常式)
| |-- FixedGridLayout (像布局)
| |-- GlobalTime (全球間)
| |-- HelloActivity (Hello)
| |-- Home (Home)
| |-- JetBoy (jetBoy游戲)
| |-- LunarLander (貌似游戲)
| |-- MailSync (郵件同步)
| |-- MultiResolution (辨率)
| |-- MySampleRss (RSS)
| |-- NotePad (記事本)
| |-- RSSReader (RSS閱讀器)
| |-- SearchableDictionary (目錄搜索)
| |-- **JNI (JNI常式)
| |-- SkeletonApp (空殼APP)
| |-- Snake (snake程序)
| |-- SoftKeyboard (軟鍵盤)
| |-- Wiktionary (維基)
| `-- Wiktionary**(維基常式)
|-- scripts (腳本)
|-- sdk (sdk配置)
|-- simulator (模擬器)
|-- testrunner (測試用)
`-- tools (些工具)
C

❷ 段錯誤的段錯誤的常見形式

編程中以下幾類做法容易導致段錯誤,基本上是錯誤地使用指針引起的。
1)訪問系統數據區,尤其是往系統保護的內存地址寫數據最常見就是給一個指針以0地址。
2)內存越界(數組越界,變數類型不一致等): 訪問到不屬於你的內存區域。
解決方法:我們在用C/C++語言寫程序的時候,內存管理的絕大部分工作都是需要我們來做的。實際上,內存管理是一個比較繁瑣的工作,無論你多高明,經驗多豐富,難免會在此處犯些小錯誤,而通常這些錯誤又是那麼的淺顯而易於消除。但是手工「除蟲」(debug),往往是效率低下且讓人厭煩的,本文將就段錯誤這個內存訪問越界的錯誤談談如何快速定位這些段錯誤的語句。
下面將就以下的一個存在段錯誤的程序介紹幾種調試方法: 1 mmy_function (void)
2 {
3 unsigned char *ptr = 0x00;
4 *ptr = 0x00;
5 }
6
7 int main (void)
8 {
9 mmy_function ();
10
11 return 0;
12 } 作為一個熟練的C/C++程序員,以上代碼的bug應該是很清楚的,因為它嘗試操作地址為0的內存區域,而這個內存區域通常是不可訪問的禁區,當然就會出錯了。我們嘗試編譯運行它: xiaosuo@gentux test $ ./a.out
段錯誤 出錯並退出。 這種方法也是被大眾所熟知並廣泛採用的方法,首先我們需要一個帶有調試信息的可執行程序,所以我們加上「-g -rdynamic的參數進行編譯,然後用gdb調試運行這個新編譯的程序,具體步驟如下: xiaosuo@gentux test $ gcc -g -rdynamic d.c
xiaosuo@gentux test $ gdb ./a.out
GNU gdb 6.5
Copyright (C) 2006 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type show ing to see the conditions.
There is absolutely no warranty for GDB. Type show warranty for details.
This GDB was configured as i686-pc-linux-gnu...Using host libthread_db library /lib/libthread
(gdb) r
Starting program: /home/xiaosuo/test/a.out
Program received signal SIGSEGV, Segmentation fault.
0x08048524 in mmy_function () at d.c:4
4 *ptr = 0x00;
(gdb) 不用一步步調試我們就找到了出錯位置d.c文件的第4行,其實就是如此的簡單。
從這里我們還發現進程是由於收到了SIGSEGV信號而結束的。通過進一步的查閱文檔(man 7 signal),我們知道SIGSEGV默認handler的動作是列印」段錯誤的出錯信息,並產生Core文件,由此我們又產生了方法二。 The default action of certain signals is to cause a process to terminate and proce a core mp file, a disk file containing an image of the process's memory at the time of termination. A list of the signals which cause a process to mp core can be found in signal(7). 以 上資料摘自man page(man 5 core)。不過奇怪了,我的系統上並沒有找到core文件。後來,憶起為了漸少系統上的垃圾文件的數量,禁止了core文件的生成,查看了以下果真如此,將系統的core文件的大小限制在512K大小,再試: xiaosuo@gentux test $ ulimit -c
0
xiaosuo@gentux test $ ulimit -c 1000
xiaosuo@gentux test $ ulimit -c
1000
xiaosuo@gentux test $ ./a.out
段錯誤 (core mped)
xiaosuo@gentux test $ ls
a.out core d.c f.c g.c pango.c test_iconv.c test_regex.c core文件終於產生了,用gdb調試一下看看吧: xiaosuo@gentux test $ gdb ./a.out core
GNU gdb 6.5
Copyright (C) 2006 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type show ing to see the conditions.
There is absolutely no warranty for GDB. Type show warranty for details.
This GDB was configured as i686-pc-linux-gnu...Using host libthread_db library /lib/libthread.
warning: Can't read pathname for load map: 輸入/輸出錯誤。
Reading symbols from /lib/lib6...done.
Loaded symbols for /lib/li6
Reading symbols from /lib/ld-.2...done.
Loaded symbols for /lib/ld-linux.s2
Core was generated by `./a.out'.
Program terminated with signal 11, Segmentation fault.
#0 0x08048524 in mmy_function () at d.c:4
4 *ptr = 0x00;dfg #include <execinfo.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
/* A mmy function to make the backtrace more interesting. */
void
mmy_function (void)
{
unsigned char *ptr = 0x00;
*ptr = 0x00;
}
void mp(int signo)
{
void *array[10];
size_t size;
char **strings;
size_t i;
size = backtrace (array, 10);
strings = backtrace_symbols (array, size);
printf (Obtained %zd stack frames. , size);
for (i = 0; i < size; i++)
printf (%s , strings[i]);
free (strings);
exit(0);
}
int
main (void)
{
signal(SIGSEGV, &mp);
mmy_function ();
return 0;
}
運行結果:xiaosuo@gentux test $ gcc -g -rdynamic g.c
xiaosuo@gentux test $ ./a.out
Obtained 5 stack frames.
./a.out(mp+0x19) [0x80486c2]
[0xffffe420]
./a.out(main+0x35) [0x804876f]

❸ 如何在 Linux 下調試動態鏈接庫

大家都知道在 Linux 可以用 gdb 來調試應用程序,當然前提是用 gcc 編譯程序時要加上
-g 參數。
我這篇文章里將討論一下用 gdb 來調試動態鏈接庫的問題。

首先,假設我們准備這樣的一個動態鏈接庫:
QUOTE:
庫名稱是: ggg
動態鏈接庫文件名是: libggg.so
頭文件是: get.h
提供這樣兩個函數調用介面:
int get ();
int set (int a);
要生成這樣一個動態鏈接庫,我們首先編寫這樣一個頭文件:
[Copy to clipboard]
CODE:
/************關於本文檔********************************************
*filename: get.h
*purpose: 一個動態鏈接庫頭文件示例
*tided by: zhoulifa() 周立發 ()
Linux 愛好者 Linux 知識傳播者 SOHO 族 開發者 最擅長 C 語言
*date time: 2006-11-15 21:11:54
*Note: 任何人可以任意復制代碼並運用這些文檔,當然包括你的商業用途
* 但請遵循 GPL
*Hope:希望越來越多的人貢獻自己的力量,為科學技術發展出力
* 科技站在巨人的肩膀上進步更快!感謝有開源前輩的貢獻!
*感謝 提供原始代碼,
我在他的基礎上整理了此文
*********************************************************************/
int get ();
int set (int a);
然後准備這樣一個生成動態鏈接庫的源文件:
[Copy to clipboard]
CODE:
/************關於本文檔********************************************
*filename: get.cpp
*purpose: 一個動態鏈接庫源文件示例
*tided by: zhoulifa() 周立發 ()
Linux 愛好者 Linux 知識傳播者 SOHO 族 開發者 最擅長 C 語言
*date time:2006-11-15 21:11:54
*Note: 任何人可以任意復制代碼並運用這些文檔,當然包括你的商業用途
* 但請遵循 GPL
*Hope:希望越來越多的人貢獻自己的力量,為科學技術發展出力
* 科技站在巨人的肩膀上進步更快!感謝有開源前輩的貢獻!
*感謝 提供原始代碼,
我在他的基礎上整理了此文
*********************************************************************/
#include <stdio.h>
#include "get.h"

static int x=0;
int get ()
{
printf ("get x=%d\n", x);
return x;
}
int set (int a)
{
printf ("set a=%d\n", a);
x = a;
return x;
}
然後我們用 GNU 的 C/C++ 編譯器來生成動態鏈接庫,編譯命令如下:
QUOTE:
g++ get.cpp -shared -g -DDEBUG -o
libggg.so

這樣我們就准備好了動態鏈接庫了,下面我們編寫一個應用程序來調用此動態鏈接庫,源代碼如下:
[Copy to clipboard]
CODE:
/************關於本文檔********************************************
*filename: pk.cpp
*purpose: 一個調用動態鏈接庫的示例
*tided by: zhoulifa() 周立發 ()
Linux 愛好者 Linux 知識傳播者 SOHO 族 開發者 最擅長 C 語言
*date time:2006-11-15 21:11:54
*Note: 任何人可以任意復制代碼並運用這些文檔,當然包括你的商業用途
* 但請遵循 GPL
*Hope:希望越來越多的人貢獻自己的力量,為科學技術發展出力
* 科技站在巨人的肩膀上進步更快!感謝有開源前輩的貢獻!
*感謝 提供原始代碼,
我在他的基礎上整理了此文
*********************************************************************/
#include <stdio.h>
#include "get.h"
int main (int argc, char** argv)
{
int a = 100;
int b = get ();
int c = set (a);
int d = get ();

printf ("a=%d,b=%d,c=%d,d=%d\n",a,b,c,d);
return 0;
}
編譯此程序用下列命令,如果已經把上面生成的 libggg.so 放到了庫文件搜索路徑指定的文件目錄,比如 /lib 或 /usr/lib 之類的,就用下面這條命令:
QUOTE:
g++ pk.cpp -o app -Wall -g -lggg
否則就用下面這條命令:
QUOTE:
g++ pk.cpp -o app -Wall -g -lggg -L`pwd`
下面我們就開始調試上面命令生成的 app 程序吧。如果已經把上面生成的 libggg.so 放到了庫文件搜索路徑指定的文件目錄,比如 /lib或 /usr/lib 之類的,調試就順利完成,如下

QUOTE:
./app
GNU gdb 6.4-debian
Copyright 2005 Free Software Foundation,Inc.
GDB is free software, covered by the GNU
General Public License, and you are
welcome to change it and/or distribute
copies of it under certain conditions.
Type "show ing" to see theconditions.

There is absolutely no warranty for GDB.
Type "show warranty" for details.This GDB was configured as "i486-linux-
gnu"...Using host libthread_db library"/lib/tls/i686/cmov/libthread_db.so.1".
(gdb) b main /* 這是在程序的 main 處設置斷點 */
Breakpoint 1 at 0x804853c: file pk.cpp,line 7.
(gdb) b set /* 這是在程序的 set 處設置斷點 */
Function "set" not defined.
Make breakpoint pending on future shared
library load? (y or [n]) y /* 這里必須選擇 y 調試程序才會跟蹤到動態鏈接庫內部去
*/Breakpoint 2 (set) pending.
(gdb) run /* 開始運行我們的程序,直到遇見斷點時暫停 */
Starting program: /data/example/c/app
Breakpoint 3 at 0xb7f665f8: file get.cpp,line 11.
Pending breakpoint "set" resolved
Breakpoint 1, main (argc=1,argv=0xbf990504) at pk.cpp:7
7 int a = 100;
(gdb) n /* 繼續執行程序的下一行代碼
*/
8 int b = get ();
(gdb) n /* 程序執行到了我們斷點所在的動態鏈接庫了 */
get x=0
9 int c = set (a);(gdb) n
Breakpoint 3, set (a=100) at get.cpp:11
11 printf ("set a=%d\n", a);
(gdb) list /* 查看當前代碼行周圍的代碼,證明我們已經跟蹤到動態鏈接庫的源代碼裡面了 */
6 printf ("get x=%d\n", x);
7 return x;
8 }
9 int set (int a)
10 {
11 printf ("set a=%d\n", a);
12 x = a;
13 return x;
14 }
(gdb) n
set a=100
12 x = a;(gdb) n
13 return x;(gdb) n
14 }
(gdb) n
main (argc=1, argv=0xbf990504) at
pk.cpp:10
10 int d = get ();
(gdb) n
get x=100
11 printf ("a=%d,b=%d,c=%
d,d=%d\n",a,b,c,d);
(gdb) n
a=100,b=0,c=100,d=100
12 return 0;
(gdb) c
Continuing.
Program exited normally.
(gdb) quit /* 程序順利執行結束 */#
如果我們沒有把動態鏈接庫放到指定目錄,比如/lib裡面,調試就會失敗,過程如下:
QUOTE:
# gdb ./app
GNU gdb 6.4-debian
Copyright 2005 Free Software Foundation,
Inc.
GDB is free software, covered by the GNU
General Public License, and you arewelcome to change it and/or distribute
copies of it under certain conditions.

Type "show ing" to see theconditions.
There is absolutely no warranty for GDB.
Type "show warranty" for details.
This GDB was configured as "i486-linux-
gnu"...Using host libthread_db library
"/lib/tls/i686/cmov/libthread_db.so.1".
(gdb) b main
Breakpoint 1 at 0x804853c: file pk.cpp,
line 7.
(gdb) b set
Function "set" not defined.
Make breakpoint pending on future shared
library load? (y or [n]) y
Breakpoint 2 (set) pending.
(gdb) run /* 雖然調試操作都一樣,但程序執行失敗 */
Starting program: /data/example/c/app
/data/example/c/app: error while loading
shared libraries: libggg.so: cannot open
shared object file: No such file or
directory
Program exited with code 0177.
(gdb) quit
#
本次實驗的環境是:
CPU:AMD Athlon(tm) 64 Processor 3000+
內存:512M
OS:Ubuntu GNU/Linux 6.06 dapper LTS
gcc:gcc 版本 4.0.3 (Ubuntu 4.0.3-1ubuntu5)

break(b) 行號:在某一行設置斷點
break 函數名:在某個函數開頭設置斷點
break...if...:設置條件斷點
continue(或c):從當前位置開始連續而非單步執行程序
delete breakpoints:刪除所有斷點
delete breakpoints n:刪除序號為n的斷點
disable breakpoints:禁用斷點
enable breakpoints:啟用斷點
info(或i) breakpoints:參看當前設置了哪些斷點
run(或r):從開始連續而非單步執行程序
display 變數名:跟蹤查看一個變數,每次停下來都顯示它的值
undisplay:取消對先前設置的那些變數的跟蹤

❹ 如何快速查找C語言代碼中的宏的值

很多的系統,代碼量超大,在我們閱讀其代碼的時候,往往macro能決定代碼執行的具體分支。利用find grep查找起來會特別慢,而且不一定能找到正確的值。如果系統是可編譯的,可以利用編譯器的預處理功能很快知道宏的具體值。

方法如下:

在CFLAGS裡面添加 -E 選項。

舉例說明:

在Android 系統裡面,

1. 在Andriod.mk裡面添加-E 參數。
LOCAL_CFLAGS += -E

2.重新編譯,顯示其過程

mm showcommands

3.編譯過程會列印出類似下面的結果。

prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/bin/arm-eabi-gcc -I hardware/ttd/marvell/generic/bmm-lib/lib -I out/target/proct/OMS_TTD/obj/SHARED_LIBRARIES/libbmm_intermediates -I system/core/include -I hardware/libhardware/include -I hardware/libhardware_legacy/include -I hardware/ril/include -I dalvik/libnativehelper/include -I frameworks/base/include -I frameworks/base/opengl/include -I external/skia/include -I out/target/proct/OMS_TTD/obj/include -I bionic/libc/arch-arm/include -I bionic/libc/include -I bionic/libstdc++/include -I bionic/libc/kernel/common -I bionic/libc/kernel/arch-arm -I bionic/libm/include -I bionic/libm/include/arch/arm -I bionic/libthread_db/include -c -fno-exceptions -Wno-multichar -msoft-float -fpic -ffunction-sections -funwind-tables -fstack-protector -fno-short-enums -march=armv5te -mtune=xscale -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__ -include system/core/include/arch/linux-arm/AndroidConfig.h -I system/core/include/arch/linux-arm/ -mthumb-interwork -DANDROID -fmessage-length=0 -W -Wall -Wno-unused -Winit-self -Wpointer-arith -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -DNDEBUG -g -Wstrict-aliasing=2 -finline-functions -fno-inline-functions-called-once -fgcse-after-reload -frerun-cse-after-loop -frename-registers -DNDEBUG -UDEBUG -DLOG_DISABLEDEBUG=1 -mthumb -Os -fomit-frame-pointer -fno-strict-aliasing -finline-limit=64 -E -MD -o out/target/proct/OMS_TTD/obj/SHARED_LIBRARIES/libbmm_intermediates/bmm_lib.o hardware/ttd/marvell/generic/bmm-lib/lib/bmm_lib.c

其中-o 是生成的文件。
打開這個文件,就是我們預編譯的結果,可以很清晰地看到各個宏的具體值。

❺ 如何編譯libboost

您好,這樣的:
1、當前boost最新版本為1.55,下載地址http://sourceforge.net/projects/boost/files/boost/1.55.0/
或者從官網(www.boost.org)下載最新版的BOOST源碼,經過測試,2012和2013步驟相同,這里以2012為例。
2、打開VS2012 Native Tools Command,可以從開始--Microsoft Visual Studio 2012找到:將下載的 boost_1_55_0.zip 解壓在F盤,例如 F:\boost_1_53_0,執行bootstrap.bat。
3、編譯,可以簡單的使用b2 install,也可以指定存放目錄,或者尋找網上其它幫助文章。
查看幫助可以輸入:.\b2 --help
比如要開啟多線程編譯:b2 install threading=multi
設置生成的是debug或者release
備註:如果是使用VS2013,請指定輸出庫類型,否則會缺一個lib文件:
"無法打開文件 libboost_thread_vc120_mt_sgd-1_55.lib"。
在2013時,我是使用下面的語句進行編譯:
// 如果要獲取動態庫:
bjam install stage --toolset=msvc-12.0 --stagedir="C:\Boost\boost_vc_120" link=shared runtime-link=shared threading=multi debug release
// 如果是要獲取靜態庫:

bjam install stage --toolset=msvc-12.0 --stagedir="C:\Boost\boost_vc_120" link=static runtime-link=static threading=multi debug release

其中,注意修改--toolset=msvc-12.0,將12.0修改成對應的vs版本號,12.0是VS2013的版本號。

目標地址也要修改成你所需的。

注意,不要漏了install,它會幫你把頭文件集合到一個文件夾中。
編譯過程有一個復制過程,編譯需要的時間比較長,本次編譯過程中,會在C盤根目錄下生成一個boost文件夾,然後包含include和lib文件夾,這就是我們將要使用的頭文件和庫文件。

4、編譯完了我們就使用編譯在C盤中的文件。我將它們拷貝到了F盤,
需要簡單的配置兩個地方:這里使用絕對路徑,也可以配置環境來使用。
5、然後建立了一個工程測試。 在BoostTest中新建一個控制台應用程序,下圖三個文件分別是:
1) 將要使用的boost頭文件和庫文件。 2) 解壓出的boost文件夾,就是使用這個文件夾來進行 1 -- 3步驟的。 3)BoostTest 測試工程。
#include <iostream>

#include <boost/thread/thread.hpp>
void hello()
{
std::cout << "Hello world, I'm a thread!" << std::endl;
}
int main()
{
boost::thread thrd(&hello);
thrd.join();
}
編譯測試工程, 並運行,開始boost之旅吧。

❻ 如何解決bus error

在x86+Linux上寫的程序,在PC機上運行得很好。可是使用ARM的gcc進行交叉編譯,再送到DaVinci目標板上運行的時候,出現了Bus error。
出現的位置如下(其中Debug的內容是我在程序中添加的調試信息):
[email protected]:~# arm_v5t_le-gcc -g shit.c
[email protected]:~# ./a.out
Debug: malloc space for the actual data: temp_buf = 0x13118
Debug: in my_recvn()
Debug: nleft = 52
Bus error
打開調試器進行調試:
[email protected]:~# gdb a.out
GNU gdb 6.3 (MontaVista 6.3-20.0.22.0501131 2005-07-22)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show ing" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "armv5tl-montavista-linuxeabi"...Using host libthread_db library "/lib/tls/libthread_db.so.1".

(gdb) run // 運行程序
Starting program: /home/zpf/a.out
Debug: in get_program_info()
Debug: in conn_server(char *err_buf_ptr)
Debug: gonna create a socket
Debug: gonna fill in the serv_addr structure
Debug: gonna connect to a server
Debug: gonna send LIN_RST
Debug: in my_sendn()
Debug: send 4 bytes to server: 
Debug: gonna receive LIN_RSP
Debug: in my_recvn()
Debug: nleft = 3
Debug: received first 3 bytes from server: 7
Debug: gonna check if 3rd byte is the package type
Debug: received package length = 55
Debug: malloc space for the actual data: temp_buf = 0x13118
Debug: in my_recvn()
Debug: nleft = 52

Program received signal SIGBUS, Bus error. // 在這里出現了錯誤
0x00009624 in alloc_prog_mem (detail_buf=0x13118 "\001\002",
err_buf_ptr=0xbefffc40 "") at shit.c:631
631 g_data_ptr->progtype_num = *(short *)ptr ;
(gdb) print ptr // 查看一下ptr的值
$1 = 0x13119 "\002" // 地址起始是奇數!!!
(gdb) set ptr=0x1311a // 想改一下
(gdb) continue
Continuing.

Program terminated with signal SIGBUS, Bus error.
The program no longer exists. // 可惜程序已經退出
(gdb) quit

其中,g_data_ptr->progtype_num是一個short類型的值。
把強制類型轉換改為用memcpy()寫值之後,再調試
[email protected]:~# gdb test
GNU gdb 6.3 (MontaVista 6.3-20.0.22.0501131 2005-07-22)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show ing" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "armv5tl-montavista-linuxeabi"...Using host libthread_db library "/lib/tls/libthread_db.so.1".

(gdb) break 626 // 把剛剛的那句強制類型轉換變成內存拷貝
Breakpoint 1 at 0x9630: file test.c, line 626.
(gdb) run
Starting program: /home/zpf/test
Debug: in get_program_info()
Debug: in conn_server(char *err_buf_ptr)
Debug: gonna create a socket
Debug: gonna fill in the serv_addr structure
Debug: gonna connect to a server
Debug: gonna send LIN_RST
Debug: in my_sendn()
Debug: send 4 bytes to server: 
Debug: gonna receive LIN_RSP
Debug: in my_recvn()
Debug: nleft = 3
Debug: received first 3 bytes from server: 7
Debug: gonna check if 3rd byte is the package type
Debug: received package length = 55
Debug: malloc space for the actual data: temp_buf = 0x13118
Debug: in my_recvn()
Debug: nleft = 52

Breakpoint 1, alloc_prog_mem (detail_buf=0x13118 "\001\002",
err_buf_ptr=0xbefffc40 "") at test.c:626
warning: Source file is more recent than executable.

626 memcpy(&(g_data_ptr->prog_num), ptr, 2) ; // 在這一句中斷
(gdb) print ptr // 再看看ptr
$1 = 0x1311b "\003" // 還是奇數地址
(gdb) continue // 繼續執行
Continuing.
Debug: sum_progtype = 2 , sum_prog = 3
Debug: gonna malloc space for progtype_ptr
Debug: gonna malloc space for prog_ptr
Debug: in mv_pkg2prog_list()
Debug: gonna set ProgramType program_type_name
Debug: ProgramType program_type_name set OK
Debug: in $ == *ptr, j = 0
Debug: g_data_ptr->progtype_ptr[j].prog_ptr = temp_prog_ptr
Debug: in @ == *ptr, ptr = 0x13126
Debug: temp_prog_ptr->format = *ptr
Debug: temp_prog_ptr->program_id = *(int *)ptr
Debug: gonna set Program program_name
Debug: Program program_name set OK
Debug: finished one loop of while
Debug: in @ == *ptr, ptr = 0x1312f
Debug: temp_prog_ptr->format = *ptr
Debug: temp_prog_ptr->program_id = *(int *)ptr
Debug: gonna set Program program_name
Debug: Program program_name set OK
Debug: finished one loop of while
Debug: gonna set ProgramType program_type_name
Debug: ProgramType program_type_name set OK
Debug: in $ == *ptr, j = 1
Debug: g_data_ptr->progtype_ptr[j].prog_ptr = temp_prog_ptr
Debug: in @ == *ptr, ptr = 0x13142
Debug: temp_prog_ptr->format = *ptr
Debug: temp_prog_ptr->program_id = *(int *)ptr
Debug: gonna set Program program_name
Debug: Program program_name set OK
Debug: finished one loop of while
program type[0]
program_type_id = 1
program_type_name = love
program_num = 2
prog_ptr = 0x131d8
program[0]
program_id = 1001
program_name = you
format = 1
program[1]
program_id = 1002
program_name = me
format = 2
program type[1]
program_type_id = 2
program_type_name = hatred
program_num = 1
prog_ptr = 0x13248
program[0]
program_id = 2005
program_name = kill
format = 5
Debug: gonna return an OK
Debug: Entering send_exit_requstion()
Debug: in conn_server(char *err_buf_ptr)
Debug: gonna create a socket
Debug: gonna fill in the serv_addr structure
Debug: gonna connect to a server
Debug: gonna send EXIT_RST
Debug: in my_sendn()
Debug: send 4 bytes to server: 
Debug: in my_recvn()
Debug: nleft = 4
Debug: gonna return an OK

Program exited normally. // 執行通過了!!!!
(gdb)

總結:
問題總算找到了,就是我企圖在一個奇數地址起始的地方強制類型轉換得到一個short值。
在Intel系列處理器上,可以在任一奇數內存地址儲存任何變數或數組,不會導致任何致命的錯誤影響,只是效率可能會降低。但在DaVinci上,這一點不行。所以必須對大於一個位元組的數據類型小心謹慎,比較安全的方法是使用內存拷貝函數memcpy(),或者使用下面的代替方法:
// 先定義一個聯合體
union {
short short_val ;
char short_byte[2] ;
} myshort ;
// 然後,把程序中本來應該是
// g_data_ptr->progtype_num = *(short *)ptr ;
// ptr += 2 ;
// 這兩句的地方換成下面五句:
myshort.short_byte[0] = *ptr ;
ptr++ ;
myshort.short_byte[1] = *ptr ;
ptr++ ;
g_data_ptr->progtype_num = myshort.short_val ;
// 當然,最簡單的方法是換成下面兩句:
// memcpy(&(g_data_ptr->progtype_num), ptr, 2) ;
// ptr += 2 ;

對於這個問題的進一步探討:
在DaVinci上應該注意內存編址模式的問題。
struct {
char struc_char ;
int struc_int ;
short struc_short ;
long struct_long ;
} struc_val ;
在寬松模式下,盡管struc_char只有1個位元組,struc_short佔2個位元組,但編譯器可能給這兩個變數分別分配了4個位元組,結果整個結構的大小變成了16個位元組,而在編譯器設為緊湊模式時,則正好是11個位元組。根據計算機數據匯流排的位數,不同的編址模式存取數據的速度不一樣。我認為在符合匯流排字長的情況下,效率是最高的,因為只需進行一次匯流排操作。
內存編址模式會影響位元組對齊方式,位元組對齊操作可以解決以下兩個主要的問題:
1.訪存效率問題;一般的編譯器要對內存進行對齊,在處理變數時,編譯器會根據一定的設置將長短不同的變數的數據長度進行對齊以加快內存處理速度。
2.強制類型轉換問題:在x86上,位元組不對齊的操作只會影響效率,但是在DaVinci上,可能就是一個Bus error, 因為它要求必須位元組對齊。
位元組對齊的准則
1.數據類型自身的對齊值:對於char型數據,其自身對齊值為1,對於short型為2,對於int,long,float,double類型,其自身對齊值為4位元組。
2.結構體的自身對齊值:其成員中自身對齊值最大的那個值。
3.指定對齊值:#pragma pack (value)時的指定對齊值value。
4.數據成員、結構體和類的有效對齊值:自身對齊值和指定對齊值中小的那個值。
對於平時定義變數,盡可能先定義長度為4的倍數的變數,然後是長度是2的變數,最後是長度為1的變數。

通過測試,GCC編譯器是按照4位元組對齊存放於內存的。而我還沒有發現更改編址模式的參數。程序如下:
#include

int main()
{
struct {
char struc_char ;
int struc_int ;
short struc_short ;
long struct_long ;
} struc_val ;
char c_char ;
int i_int ;
short s_short ;
long l_long ;

printf("sizeof(struc_val) = %d\n", sizeof(struc_val));
printf("sizeof(c_char) = %d\n", sizeof(c_char));
printf("sizeof(i_int) = %d\n", sizeof(i_int));
printf("sizeof(s_short) = %d\n", sizeof(s_short));
printf("sizeof(l_long) = %d\n", sizeof(l_long));

printf("address of struc_val = %p\n", &struc_val);
printf("address of struc_char = %p\n", &(struc_val.struc_char));
printf("address of struc_int = %p\n", &(struc_val.struc_int));
printf("address of struc_short = %p\n", &(struc_val.struc_short));
printf("address of struct_long = %p\n", &(struc_val.struct_long));
printf("address of c_char = %p\n", &c_char);
printf("address of i_int = %p\n", &i_int);
printf("address of s_short = %p\n", &s_short);
printf("address of l_long = %p\n", &l_long);

return 0 ;
}
測試結果:
sizeof(struc_val) = 16
sizeof(c_char) = 1
sizeof(i_int) = 4
sizeof(s_short) = 2
sizeof(l_long) = 4
address of struc_val = 0xbf885278
address of struc_char = 0xbf885278
address of struc_int = 0xbf88527c
address of struc_short = 0xbf885280
address of struct_long = 0xbf885284
address of c_char = 0xbf885277
address of i_int = 0xbf885270
address of s_short = 0xbf88526e
address of l_long = 0xbf885268

所以對於一個32位的數據來講,如果其沒有在4位元組整除的內存地址處存放,那麼處理器就需要2個匯流排周期對其進行訪問。
0x08 | byte8 | byte9 | byteA | byteB |
0x04 | byte4 | byte5 | byte6 | byte7 |
0x00 | byte0 | byte1 | byte2 | byte3 |
對於我剛剛的那個出現Bus error的程序,假設指針ptr剛好是指向了byte3(地址是0x0),然後想進行short強制類型轉換,使用byte3,byte4來構成一個short類型的值,由於第一次匯流排的數據只有byte0,byte1,byte2,byte3,取不到byte4,這在DaVinci板子上,就是一個Bus error了,因為沒有達到邊界對齊。如果ptr指的是byte2(地址0x02),就沒有問題了。因為0x02地址值是sizeof(short)的整數倍。

❼ android 源碼 怎麼只編譯 systemui

Google提供的Android包含了原始Android的目標機代碼,主機編譯工具、模擬環境,下載的代碼包經過解壓後(這里是Android2.2的源碼包),源代碼的第一層目錄結構如下: -- Makefile -- bionic (bionic C庫) -- bootable (啟動引導相關代碼) -- build (存放系統編譯規則及generic等基礎開發包配置) -- cts (Android兼容性測試套件標准) -- dalvik (dalvik JAVA虛擬機) -- development (應用程序開發相關) -- external (android使用的一些開源的模組) -- frameworks (核心框架——java及C++語言) -- hardware (主要保護硬解適配層HAL代碼) -- libcore -- ndk -- device -- out (編譯完成後的代碼輸出與此目錄) -- packages (應用程序包) -- prebuilt (x86和arm架構下預編譯的一些資源) -- sdk (sdk及模擬器) -- system (文件系統庫、應用及組件——C語言) `-- vendor (廠商定製代碼) bionic 目錄 -- libc (C庫) -- arch-arm (ARM架構,包含系統調用匯編實現) -- arch-x86 (x86架構,包含系統調用匯編實現) -- bionic (由C實現的功能,架構無關) -- docs (文檔) -- include (頭文件) -- inet -- kernel (Linux內核中的一些頭文件) -- netbsd (?netbsd系統相關,具體作用不明) -- private (?一些私有的頭文件) -- stdio (stdio實現) -- stdlib (stdlib實現) -- string (string函數實現) -- tools (幾個工具) -- tzcode (時區相關代碼) -- unistd (unistd實現) `-- zoneinfo (時區信息) -- libdl (libdl實現,dl是動態鏈接,提供訪問動態鏈接庫的功能) -- libm (libm數學庫的實現,) -- alpha (apaha架構) -- amd64 (amd64架構) -- arm (arm架構) -- bsdsrc (?bsd的源碼) -- i386 (i386架構) -- i387 (i387架構?) -- ia64 (ia64架構) -- include (頭文件) -- man (數學函數,後綴名為.3,一些為freeBSD的庫文件) -- powerpc (powerpc架構) -- sparc64 (sparc64架構) `-- src (源代碼) -- libstdc++ (libstdc++ C++實現庫) -- include (頭文件) `-- src (源碼) -- libthread_db (多線程程序的調試器庫) `-- include (頭文件) `-- linker (動態鏈接器) `-- arch (支持arm和x86兩種架構) bootable 目錄 -- bootloader (適合各種bootloader的通用代碼) `-- legacy (估計不能直接使用,可以參考) -- arch_armv6 (V6架構,幾個簡單的匯編文件) -- arch_msm7k (高通7k處理器架構的幾個基本驅動) -- include (通用頭文件和高通7k架構頭文件) -- libboot (啟動庫,都寫得很簡單) -- libc (一些常用的c函數) -- nandwrite (nandwirte函數實現) `-- usbloader (usbloader實現) -- diskinstaller (android鏡像打包器,x86可生產iso) `-- recovery (系統恢復相關) -- edify (升級腳本使用的edify腳本語言) -- etc (init.rc恢復腳本) -- minui (一個簡單的UI) -- minzip (一個簡單的壓縮工具) -- mttils (mtd工具) -- res (資源) `-- images (一些圖片) -- tools (工具) `-- ota (OTA Over The Air Updates升級工具) `-- updater (升級器) build目錄 -- core (核心編譯規則) -- history (歷史記錄) -- libs `-- host (主機端庫,有android 「cp」功能替換) -- target (目標機編譯對象) -- board (開發平台) -- emulator (模擬器) -- generic (通用) -- idea6410 (自己添加的) `-- sim (最簡單) `-- proct (開發平台對應的編譯規則) `-- security (密鑰相關) `-- tools (編譯中主機使用的工具及腳本) -- acp (Android "acp" Command) -- apicheck (api檢查工具) -- applypatch (補丁工具) -- apriori (預鏈接工具) -- atree (tree工具) -- bin2asm (bin轉換為asm工具) -- check_prereq (檢查編譯時間戳工具) -- dexpreopt (模擬器相關工具,具體功能不明) -- droiddoc (?作用不明,java語言,網上有人說和JDK5有關) -- fs_config (This program takes a list of files and directories) -- fs_get_stats (獲取文件系統狀態) -- iself (判斷是否ELF格式) -- isprelinked (判斷是否prelinked) -- kcm (按鍵相關) -- lsd (List symbol dependencies) -- releasetools (生成鏡像的工具及腳本) -- rgb2565 (rgb轉換為565) -- signapk (apk簽名工具) -- soslim (strip工具) `-- zipalign (zip archive alignment tool) dalvik目錄 dalvik虛擬機 . -- dalvikvm (main.c的目錄) -- dexmp (dex反匯編) -- dexlist (List all methods in all concrete classes in a DEX file.) -- dexopt (預驗證與優化) -- docs (文檔) -- dvz (和zygote相關的一個命令) -- dx (dx工具,將多個java轉換為dex) -- hit (?java語言寫成) -- libcore (核心庫) -- libcore-disabled (?禁用的庫) -- libdex (dex的庫) -- libnativehelper (Support functions for Android's class libraries) -- tests (測試代碼) -- tools (工具) `-- vm (虛擬機實現) development 目錄 (開發者需要的一些常式及工具) -- apps (一些核心應用程序) -- BluetoothDebug (藍牙調試程序) -- CustomLocale (自定義區域設置) -- Development (開發) -- Fallback (和語言相關的一個程序) -- FontLab (字型檔) -- GestureBuilder (手勢動作) -- NinePatchLab (?) -- OBJViewer (OBJ查看器) -- SdkSetup (SDK安裝器) -- SpareParts (高級設置) -- Term (遠程登錄) `-- launchperf (?) -- build (編譯腳本模板) -- cmds (有個monkey工具) -- data (配置數據) -- docs (文檔) -- host (主機端USB驅動等) -- ide (集成開發環境) -- ndk (本地開發套件——c語言開發套件) -- pdk (Plug Development Kit) -- samples (演示程序) -- AliasActivity () -- ApiDemos (API演示程序) -- BluetoothChat (藍牙聊天) -- BrowserPlugin (瀏覽器插件) -- BusinessCard (商業卡) -- Compass (指南針) -- ContactManager (聯系人管理器) -- CubeLiveWall** (動態壁紙的一個簡單常式) -- FixedGridLayout (像是布局) -- GlobalTime (全球時間) -- HelloActivity (Hello) -- Home (Home) -- JetBoy (jetBoy游戲) -- LunarLander (貌似又是一個游戲) -- MailSync (郵件同步) -- MultiResolution (多解析度) -- MySampleRss (RSS) -- NotePad (記事本) -- RSSReader (RSS閱讀器) -- SearchableDictionary (目錄搜索) -- **JNI (JNI常式) -- SkeletonApp (空殼APP) -- Snake (snake程序) -- SoftKeyboard (軟鍵盤) -- Wiktionary (?維基) `-- Wiktionary**(?維基常式) -- scripts (腳本) -- sdk (sdk配置) -- simulator (?模擬器) -- testrunner (?測試用) `-- tools (一些工具)

❽ liunx 下ngnix在用gdb調試遇到下面問題,有大神知道怎麼解的嗎

  1. GDB作為一個強大的c/c++調試工具,一直是程序猿們的良好伴侶,但轉到Mac os才發現竟然沒有默認安裝,所幸還有強大的homebrew工具:brew install homebrew/pes/gdb

  2. 然後就是漫長的等待+編譯安裝時間了,安裝完成後敲擊gdb能列印出版本信息,說明已經正確安裝了

2.生成證書,這是由於Mac os的安全機制阻止了gdb對要調試的程序進行完全控制,對此我們要對gdb賦予合適的許可權,首先我們要在keychain access裡面添加相應的keychain (鑰匙串)。

3.選擇"always trust"我們剛生成的證書,這樣就不用每次在運行gdb的時候手工輸入管理員密碼了

4.對gdb進行證書簽名。

5.打開activity monitor, 在cpu一欄的搜索框中輸入『taskgated』,然後雙擊進程所在行,點選『quit』,這是你會發現taskgated進程消失了(好無辜的一個進程:( )。現在就可以對gdb進行簽名了:codesign -s gdb-cert /usr/local/bin/gdb

❾ docker中使用JDK工具jmap報錯

docker中,jdk用鏡像配置環境變數的方法如下:
一、安裝 JDK
1、首先,解壓 JDK 程序包:
tar -zxf /mnt/software/jdk-7u67-linux-x64.tar.gz -C .

2、重命名 JDK 目錄:
mv jdk1.7.0_67/ jdk/

二、設置環境變數
首先,編輯.bashrc文件
vi ~/.bashrc

然後,在該文件末尾添加如下配置:
export JAVA_HOME=/opt/jdk
export PATH=$PATH:$JAVA_HOME

最後,需要使用source命令,讓環境變數生效:
source ~/.bashrc

❿ 如何解決bus error

一,Bus Error究竟是指什麼

Bus Error,即匯流排錯誤。

引發原因:

CPU處於性能方面的考慮,要求對數據進行訪問時都必須是地址對齊的。如果發現進行的不是地址對齊的訪問,就會發送SIGBUS信號給進程,使進程產生 core mp。RISC包括SPARC(一種微處理器架構)都是這種類型的晶元。x86系列CPU都支持不對齊訪問,也提供了開關禁用這個機制。x86架構不要求對齊訪問的時候,必定會有性能代價。例如,對int的訪問應該是4位元組對齊的,即地址應該是4的倍數,對short則是2位元組對齊的,地址應該是2的倍數。

Bus Error也有可能是因為機器物理問題或者訪問無效物理地址,但這種情況非常少見。

Linux平台上執行malloc(),如果沒有足夠的RAM,Linux不是讓malloc()失敗返回,而是向當前進程分發SIGBUS信號。
注: 對該點執懷疑態度,有機會可自行測試確認當前系統反應。

SIGBUS與SIGSEGV信號的一般區別如下:

1) SIGBUS(Bus error)意味著指針所對應的地址是有效地址,但匯流排不能正常使用該指針。通常是未對齊的數據訪問所致。

2) SIGSEGV(Segment fault)意味著指針所對應的地址是無效地址,沒有物理內存對應該地址。

二,例子程序:

1 int main(){
2
3
4
5
6 #if defined(__GNUC__)
7 # if defined(__i386__)
8
9 __asm__("pushf/norl $0x40000,(%esp)/npopf");
10 # elif defined(__x86_64__)
11
12 __asm__("pushf/norl $0x40000,(%rsp)/npopf");
13 # endif
14 #endif
15
16
17
18
19
20
21
22
23
24 short array[16];
25
26 int * p = (int *) &array[1];
27 *p = 1;
28
29 return 1;
30 }

short類型大小為2個位元組,其地址必是2的倍數。而對於int指針來說,能夠使用以訪問數據的地址應該是4的倍數,轉化arrary[1]的地址為int *並訪問,系統會發出SIGBUS信號,導致程序崩潰。

wiki上的例子:

http://en.wikipedia.org/wiki/Bus_error#Bus_error_example
#include <stdlib.h>

int main( int argc, char ** argv) {
int * iptr;
char * cptr;

#if defined(__GNUC__)
# if defined(__i386__)

__asm__( "pushf/n orl $0x40000,(%esp)/n popf" ) ;
# elif defined(__x86_64__)

__asm__( "pushf/n orl $0x40000,(%rsp)/n popf" ) ;
# endif
#endif

cptr = malloc( sizeof ( int ) + 1) ;

iptr = ( int * ) ++ cptr;

* iptr = 42 ;

return 0 ;
}
$ gcc -ansi sigbus.c -o sigbus
$ ./sigbus
Bus error
$ gdb ./sigbus
(gdb) r
Program received signal SIGBUS , Bus error.
0x080483ba in main ()
(gdb) x/i $pc
0x80483ba <main+54>: mov DWORD PTR [eax],0x2a
(gdb) p/x $eax
$1 = 0x804a009
(gdb) p/t $eax & (sizeof(int) - 1)
$2 = 1

三,編譯器和硬體平台相關性

上述已經描述,對於x86平台,默認允許非對齊訪問,只不過會有性能代價。開啟檢測可以使用上述代碼中的宏。

這段程序如果用Sun Studio編譯器的話,運行就沒有問題。這是因為Sun Studio默認對32位編譯使用的參數是-xmemalign=8i,其中i選項設置明確指明不產生SIGBUS信號。
不過如果編譯成64位程序,Sun Studio使用的-xmemalign=8s,其中s選項設置意味對這種非對齊訪問產生SIGBUS信號,則仍舊會遇到這個錯誤。

如果堅持在SPARC上使用GCC去編譯這種代碼,可以如下進行:
GCC有一個Type Attributes特性,例如在需人工對齊的變數後加上:__attribute__ ((aligned (4))); 其意義就是指定偏移量為4的倍數。比如:
short array[10] __attribute__ ((aligned (4)));

不過這個屬性只對Linker連接器可見的變數有效,也就是說對local variable無效。而且這種特性作用粒度比較大,比如這里只對第一個元素有作用,並不為數組的每個成員設置偏移量。如果一定要針對local variable或者數組的每個成員進行偏移量設置,可以使用union類型:
union {
short s;
int i;
}

閱讀全文

與編譯libthreaddb相關的資料

熱點內容
股市中帶星號的app是什麼 瀏覽:707
什麼路由可以刷機做列印機伺服器 瀏覽:5
電腦怎麼找到雲伺服器 瀏覽:871
微信怎麼發應用app 瀏覽:776
花生殼dns伺服器地址 瀏覽:648
squad伺服器一般什麼時候人多 瀏覽:479
程序員戰門課 瀏覽:474
config保存伺服器地址 瀏覽:317
預訂網吧座位的app叫什麼 瀏覽:416
香港伺服器主機地址 瀏覽:640
網店美工pdf 瀏覽:447
一堆文件夾怎麼弄出來 瀏覽:743
博途如何編譯硬體 瀏覽:418
fortran程序pdf 瀏覽:504
電池消耗演算法 瀏覽:394
伺服器中斷連接怎麼處理 瀏覽:222
上世紀互聯網不發達程序員很難 瀏覽:841
語音識別android開源 瀏覽:762
地埋式垃圾壓縮中轉站 瀏覽:902
apachehttpdlinux 瀏覽:944