Selected Category: tech (5)

View Mode: Post List Post Summary
git push 原本預設的行為是沒啥問題就直接送進遠端的repo,但這是有一個潛在的風險,當遠端的repo不是bare(請看git clone --help)而遠端的使用者用正在改working tree時,會造成working tree的base異動(會發生啥事?)。大大們承認這是當初設計上的失誤,想在之後的版本上修正,但又不想像1.6.0 把 '-'拿掉搞的天怒人怨,要來個漸進式的招術

在1.6.4,當push 回一個 non-bare 的repo 時,會產生警告,但是還是讓你丟進去
在1.6.5後,預設的值是拒絕。

可以在遠端的設定檔的

receive.denyCurrentBranch # true/refuse, warn, false/ignore
receive.denyDeletes # for branch delete


加以設定

詳細可看1.6.4 releasenotes

murmur: 不知不覺git 的版本已經來到 1.6.4,ubuntu的官方package 還在 1.6.0.4,什麼時候才會更新阿 @@~


Posted by cmchao at 痞客邦 PIXNET Comments(0) Trackback(0) Hits(95)

C++0x 引進了一個新的標準r-value reference 號稱可以大大的增進程式的效能。上星期Visual C++ Team 發表了一篇STL Performance 談到他們運用在VS 2010 和自已的STL library 上的成果。如果以vector的insertion和reallocation來看的話,大概可以快 2 ~ 3 倍。

至於什麼是R-value reference呢?有興趣的可以看Rvalue References: C++0x Features in VC10, Part 2,不想看英文的可以參考ptt's yoco315 翻譯的中文版

Posted by cmchao at 痞客邦 PIXNET Comments(0) Trackback(0) Hits(178)

回別人的文順便貼一下

Q: 要怎麼更動set 中element 的內容呢?
A: Visual C++ Team Blog 昨天也有提到這個問題
請看問題三:http://0rz.tw/TNBKr
在C++98/03 中,使用者是可以任意更改元素的值,只要不要改變元素順序
但在C++0x,明確的限制了這件事

"Keys in an associative container are immutable" (N2857 23.2.4/5) and "For
[set and multiset], both iterator and const_iterator are
constant iterators"

他提出了四種解法
1 改用 map/multimap,分離key 和value
2 刪掉改一改再塞一個新的進去
3 改用 set/multiset, comparator>,多一層轉換
4 上一篇推文中提到的 mutable (作者這說很怪 weird),
const_cast (作者說這很邪惡 evil)

雖然 C++0x 都快變成C++1x了,還是要尊重一下...:P

Posted by cmchao at 痞客邦 PIXNET Comments(0) Trackback(0) Hits(60)

全文90% 參考Ubuntu - 建立 ARM Toolchain (Cross Compiler)
不一樣的部份就是版本比他用的更新,然後提一下碰到的問題

環境:乾淨的ubuntu 9.04

step 1:安裝額外的套件,有些名字不太對,自已改一下


build-essential (gcc glibc)
bison (binutils and gcc )
flex (binutils and gcc)
texinfo (makeinfo
libncurses5-dev ( termcap)
mpfr-dev (gcc build)
gmp-dev (gcc build)


step 2 : 下載source package,解壓縮到目錄
binutils-2.19.1
gcc-4.4.0
newlib-1.17.0
gdb-6.8


step 3 : 設定編譯環境
TARGET_DIR 和 LIB_SRC請依照你安裝位置和源始碼放位置修改

export TARGET_DIR="/usr/local/gnuarm"
export LIB_SRC="/home/maxkerr/gnuarm/newlib-1.14.0"
export MY_CONFIG="--target=arm-elf --prefix=$TARGET_DIR --enable-interwork --enable-multilib"
export GCC_CONFIG="--target=arm-elf --prefix=$TARGET_DIR --enable-interwork --enable-multilib --enable-languages=c,c++ --with-newlib --with-headers=$LIB_SRC/newlib/libc/include"
export PATH="$PATH:$TARGET_DIR/bin"


step 4 : 編譯 binutils
套用patch,一個debug function format error

cd binutils-2.19.1
mkdir build;cd build
../configure $MY_CONFIG
sudo make -j 4 all install


step 5 : 編譯 gcc part 1

cd gcc-4.4.0
mkdir build;cd build
../configure $GCC_CONFIG
sudo make all-gcc install-gcc


step 6 : 編譯 newlib

cd newlib-0.17.0
mkdir build;cd build
../configure $MY_CONFIG
make all
sudo -c
export PATH="$PATH:$TARGET_DIR/bin" (為了找到arm-elf-cc)
make install



step 7 : 編譯 gcc part 2

cd gcc-4.4.0/build
sudo make all install


step 8 : 編譯 gdb
套用修正 p1, p2, p3, p4, p5, p6,

cd gdb-6.8
mkdir build;cd build
../configure $MY_CONFIG
sudo make all install


step 9 : 設定運行環境
把 :/usr/local/gnuarm/bin 加到 /etc/environment 中 PATH 最後一個 " 之前,例如這樣:
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/gnuarm/bin"

step 10 : 測試

arm-elf-cc hello.c
arm-elf-run a.out

Posted by cmchao at 痞客邦 PIXNET Comments(0) Trackback(0) Hits(544)

之前jserv寫了篇很有趣的文章(Who Call Me ?),利用一些小技巧去取caller和callee 之間的information。不過每個trace 的地方都還要手動塞code,如果要在往上看再去看stack frame,我對x86實在是很不熟。


今天在寫profiling的東東想到是不是可以用instrumentation(註一)的方式來得到同樣的資訊,把whocallme 的call 塞到每個function裡。原本以為-pg(gprof)可以做得到,因為gprof本來就是利用偷塞一些code來統計資訊,但gcc似乎不允許你塞自已的function。


那有其它的方式嗎?果然gcc support -finstrument-functions這個選項,會在你所有function 前後各塞入一個function,讓user可以蒐集或輸出一些資訊



void __cyg_profile_func_enter (void *this_fn, void *call_site);
void __cyg_profile_func_exit   (void *this_fn, void *call_site);



使用方式呢?這種技巧jserv 去年已經介紹過了,請看這裡。那現在就是把他們組合起來啦,底下是patch


--- ../whocallme/whocallme.c    2008-07-30 13:57:30.000000000 +0800
+++ ../whocallme2/whocallme.c   2008-08-20 17:59:23.000000000 +0800
@@ -60,7 +60,7 @@
{
    int i;
    for (i = 0; i < table_count; i++) {
-       if (addr > fun_table[i].addr) {
+       if (addr >= fun_table[i].addr) {
            if (addr < fun_table[i + 1].addr)
                return fun_table[i].name;
        }
@@ -134,3 +134,12 @@
    qsort(fun_table, table_count, sizeof(FUN_TABLE), compare_function);
    return 0;
}
+
+#define DUMP(func, call) \
+        printf("%s: func = %s, called by = %s\n", __FUNCTION__, func, call)
+
+void __attribute__((__no_instrument_function__))__cyg_profile_func_enter(void *this_func, void *call_site)
+{
+        DUMP(find_function_by_addr((unsigned long)this_func),
+        find_function_by_addr((unsigned long)call_site));
+}


 


在編譯你自已的程式時加入 -finstrument-functions(編譯whocallme.c 的時候不用,不然每個function 都要再補上no_instrucment_function的 attribute


,然後輸出就會長成這樣,


__cyg_profile_func_enter: func = test, called by = main
__cyg_profile_func_enter: func = test_a, called by = main
__cyg_profile_func_enter: func = test_b, called by = test_a
__cyg_profile_func_enter: func = test, called by = test_b
__cyg_profile_func_enter: func = test_c, called by = test_a
__cyg_profile_func_enter: func = test_b, called by = main
__cyg_profile_func_enter: func = test, called by = test_b
__cyg_profile_func_enter: func = test_c, called by = main


註一:instrumentation 要翻成啥?,"中山山"好像不錯

Posted by cmchao at 痞客邦 PIXNET Comments(0) Trackback(0) Hits(139)