StackEdit 測試

這是標題

This is a source code - of course - a C++ hello world.

#include <iostream>

int main( int argc, char* argv[] )
{
    std::cout << "Hello World" << std::endl;
    return 0;
}

看起來還不錯,真希望有 native editor 版本 …

Written with StackEdit.

auto + braced-init-list 在 direct initialization 和 copy initialization 中的差異

C++17 中有條修改 n3922 細想之後挺有意思的。 C++11 中規定,下面的程式碼會推導出一個 std::initializer_list<int>:
auto i{ 10 }; // i is a std::initializer_list<int>
當初在 C++11 看到時,覺得的確不太直覺,但當時記性還行,索性就記得說:新語言特性(auto)喜歡跟新語言特性(initializer_list)一起。後來在 C++17 中修改了,
For direct list-initialization:

1. For a braced-init-list with only a single element, auto deduction will deduce from that entry;
2. For a braced-init-list with more than one element, auto deduction will be ill-formed.
也就是說,C++17 後變成了: auto + direct initialization + braced-init-list 只能初始化單一一個變數。
auto i{ 10 }; // legal and i is a std::initialize_list<int>
auto i{ 10, 11 }; // illegal
岔題一下:auto + direct initialization + braced-init-list 沒辦法用在 C-style array 上,所以下面在 C++11 和 C++17 都是非法的。
auto array[]{ 10, 11 }; // illegal
auto array2[ 2 ]{ 10, 11 }; // illegal
但如果今天場景變成 auto + copy initialization + braced-init-list 那就總是會定義出一個 std::initialize_list<int> 變數了。
auto i = { 10 }; // legal and i is a std::initializer_list<int>
auto array = { 10, 11 }; // legal and array is a std::initializer_list<int>
哎,那這次要怎麼記得這件規則呢?顧名思義:等號右邊是 braced-init-list ,所以它原本就是 std::initialize_list<int> ,那既然是 copy initialization 。那就連型別也一起 copy 吧~真是太哲學了! 好吧,因為是哲學,所以有點不太科學:return value 可以視為一種 copy initialization ,但這情況下,是不能使用 auto 推導出 std::initialize_list<int> 的,因為 braced-init-list 不是一個 expression ,並不會產生一個 value [1] 。因此 return type 需要一個明確的型別來搭配,並用來呼叫 return type 的 constructor 的 ...
auto f()
{
    return {1,2}; // ill-formed, {1,2} is not an expression
}
...

Use bu in WinDbg and get `Couldn't resolve error at module!func`

在 WinDbg 中設定 breakpoint 時如果遇到 symbol mismatching ,那 WinDbg 就會提示 Couldn't resolve error at module!func 。不過有趣的是,如果今天是用 bu module!func 也遇到一樣的問題,那還會是 symbol not found 嗎?如果此時 stack 是停在 nt!DebugService2 時,那就很有可能也是 symbol not found 了。
0: kd> bu module!func

0: kd> g
Breakpoint 0's offset expression evaluation failed.
Check for invalid symbols or bad syntax.
WaitForEvent failed
nt!DebugService2+0x6:
fffff806`31805296 c3              ret

1: kd> k
 # Child-SP          RetAddr           Call Site
00 ffffde00`16226b68 fffff806`31771955 nt!DebugService2+0x6
01 ffffde00`16226b70 fffff806`317718e7 nt!DbgLoadImageSymbols+0x45
02 ffffde00`16226bc0 fffff806`31b558f1 nt!DbgLoadImageSymbolsUnicode+0x33
03 ffffde00`16226c00 fffff806`31b55423 nt!MiDriverLoadSucceeded+0x18d
04 ffffde00`16226ca0 fffff806`31b54c06 nt!MmLoadSystemImageEx+0x807
05 ffffde00`16226e40 fffff806`31b3800c nt!MmLoadSystemImage+0x26
06 ffffde00`16226e80 fffff806`31b36f22 nt!IopLoadDriver+0x23c
07 ffffde00`16227050 fffff806`31b36c32 nt!PipCallDriverAddDeviceQueryRoutine+0x1be
08 ffffde00`162270e0 fffff806`31b365f0 nt!PnpCallDriverQueryServiceHelper+0xda
09 ffffde00`16227190 fffff806`31b35d83 nt!PipCallDriverAddDevice+0x41c
0a ffffde00`16227350 fffff806`31b2fcc6 nt!PipProcessDevNodeTree+0x333
0b ffffde00`16227420 fffff806`3176efba nt!PiRestartDevice+0xba
0c ffffde00`16227470 fffff806`3168e5c5 nt!PnpDeviceActionWorker+0x46a
0d ffffde00`16227530 fffff806`317265f5 nt!ExpWorkerThread+0x105
0e ffffde00`162275d0 fffff806`318048d8 nt!PspSystemThreadStartup+0x55
0f ffffde00`16227620 00000000`00000000 nt!KiStartSystemThread+0x28

1: kd> bc *

1: kd> bu module!func
Couldn't resolve error at 'vmodule!func'

為什麼呢?此時不是使用 Set Unresolved Breakpoint 嗎?嗯嗯,Unresolved Breakpoint 也是有需要 resolve 的時候,剛好系統正在載入新 module ,而且符合 bu 指定的 module name ,那就會開始 resolve symbol name ,如果找不到一樣會跳出 Couldn't resolve error at 'vmodule!func' 了。

boost.test BOOST_CHECK_EXCEPTION 竟然不支援 lambda

如題 BOOST_CHECK_EXCEPTION 竟然不支援用 lambda 寫 predicator ...
	
    BOOST_CHECK_EXCEPTION(
        p.parseString("---\n---"),
        durin::yaml::ParserException, 
        []( const durin::yaml::ParserException& ex ) {
        	return ex.what() == std::string( "Double DocBegin" );
        });
	
Feel so sad ...

KDE Craft 初試

雖然越來越多的 web-based UML editor 可以用,而且感覺 portability 也不錯,不像 native editor 可能還會被綁死在特定 file format 上,不過怎麼說呢?細節上的操作性還是有差,以前工作 Windows only ,用還是 open source 版本的 StarUML 也是挺愜意的,但隨著 MacOS, Linux 近來攪和後,就屬意了 Umbrello ,只是好像有時候不是很穩定,想來自己貢獻一下,沒想到 KDE 貌似就有兩套 build tool,craft 和 kdesrc-build ,太折騰了… craft 用 python 寫的,比起 kdesrc-build 用 perl ,那還是玩玩看 craft 吧,沒想到還是要用到 python27 Orz ...

Native Blog Editor

唉唉,2021都要結束了,找個 blog friendly 的 native editor 還是很困難,應該說從來沒簡單過,加上又是一個時代的結束…

Mismatch between lldb and clang on vscode

Mismatch between lldb and clang on vscode

奇怪,今天嘗試在 vscode 中使用 lldb live debug 一個 C++ 程式,斷點下好後卻卡住了。

Console 的錯誤訊息是:bind: Invalid command `enable-meta-key’.

上網查了一下,貌似 vscode、 QtCreator 都有災情。

  1. https://github.com/vadimcn/vscode-lldb/issues/141
  2. https://bugreports.qt.io/browse/QTCREATORBUG-21615

追了一下才發現,自己的環境有兩份 clang ,分別是 6.0 和 8.0 。單純抄 vscode + C/C++ 的官方文件可能會導致 compiler 和 debugger 的版本不合,另外 miDebugerPath 似乎也要更新成使用 lldb-mi 版本,不然會有以下錯誤。

warning: ignoring unknown option: --interpreter=mi
warning: ignoring unknown option: --tty=/dev/pts/19

最終可用環境是:
ubuntu Ubuntu 18.04.1 LTS
vscode 1.42.1
C/C++ Extension 0.26.3
lldb 8
clang 8

{
    "MIMode": "lldb",
    "miDebuggerPath": "/usr/bin/lldb-mi-8"
}

vscode menu bar 修改

kde neon 上的 vscode 貌似在自動更新後,native menu bar 的字體顏色變得跟 native theme 的顏色太接近,人眼幾乎沒辦法看出字來。
模糊的 menu bar調整了一下系統的 theme或是調整 dark mode 都沒有用。好在 menu bar 可以改成 vscode 自己畫。

  1. File > Preferences > Settings (or Ctrl+Shift+P > Preferences: Open Settings (UI))
  2. 用 window.titlebarbarstyle 當作 search settings 的關鍵字。
  3. 將 native 改成 custom,重開 vscode 就好了。

Reference

  1. Change Visual Studio Code’s title bar color

2020

復活吧,我的 blog

LLVM for Windows Visual Studio 2010/2012

Chandler Caruth 在 GoingNative 2013 上宣布了一個好消息,LLVM 3.4 (開發中)正在如火如荼地移植到 Windows 上,目前初步的成果已經可以使用 Visual Studio 2010/2012 作為 IDE 了,對於習慣 Visual Studio 的人來講應該是個好消息。

alpha 版本可以在這邊下載到:

  • SVN Snapshot: http://llvm.org/builds/
  • 設定上也非常簡單,在 Project > Properties > General > Platform Toolset 改成 LLVM-vs2010 即可。
    llvm_on_windows

試玩了一下發現:

新 project 有感

C# + .NET framework 2.0 + Visual Studio 2010 + remote debugging = 殘廢

C# + .NET framework 2.0 + dump + WinDbg = 悲劇

NetBSD Kernel 要支援 Lua

讓我想起了以前微軟研究院利用 C# 改良版 Spec# 開發的 Singularity OS ,不過這次換成了 Lua 。

2010 年便開始開始的 GSoC project,一度變成沒人維護的項目,不過 NetBSD 7 可能即將包含它。還提到了 Python 和 Java 也是有可能的取代方案,不過考慮到這兩個語言的 object mapping 和 memory 需求量,還是沒有成真。

目前看來外國鄉民是一面倒地不看好,不過技術嘛,或許會有令人驚豔的應用或影響出現也說不定!不過 script language 大都帶有 garbage collection ,要讓這大傢伙和 kernel 裡其他的 subsystem 互動順利、尤其是記憶體管理,加上處理 interpreter 內,自帶的 synchronization mechanism 搭配 kernel scheduler ,花的功夫應該是不少,令人好奇!

News http://bsd.slashdot.org/story/13/02/16/2329259/netbsd-to-support-kernel-development-in-lua-scripting

Slides: https://fosdem.org/2013/schedule/event/lua_in_the_netbsd_kernel/attachments/slides/278/export/events/attachments/lua_in_the_netbsd_kernel/slides/278/kernel_mode_lua.pdf

BoostPro 要關門了?!

在 Boost mail list 上看到的消息:

http://lists.boost.org/Archives/boost/2013/01/200634.php


Subject: [boost] Future of Boost Windows Installers
From: Dave Abrahams (dave_at_[hidden])
Date: 2013-01-31 14:42:33

Hi,

As many of you already know, I'm going to work at Apple in late
February, and BoostPro is closing its doors. For many years, the Boost
Getting Started Guide has suggested that Windows users pop over to
BoostPro's website and use the latest installer to get Windows binaries.
We'd like to donate to the community the technology used to build those
installers. If anyone would like to pick up the job of creating them,
we'd be happy to offer guidance.

Right now I'm on a plane where an uplink to GitHub is creeping along at
4KB/s, so I've been pushing the stuff up in bits and pieces and the
latest stuff isn't up there, but it's going to
http://github.com/boostpro/installer and will be complete within 24 hours.

Whatever happens with this installer code, someone is going to need to
update the Getting Started Guide, either to point at the installer's new
home, or to remove references to it.

-- 
Dave Abrahams
BoostPro Computing                  Software Development        Training
http://www.boostpro.com             Clang/LLVM/EDG Compilers  C++  Boost

BoostPro 是幾位 C++ 大師組成的教學顧問團隊,BoostPro 上有他們的黃金陣容的介紹:

  • Dave Abrahams
    多年來致力於 C++ 標準制定和 Boost 推廣維護,貢獻了很多 Boost libraries、2001 年創辦 BoostPro 、
  • Joel de Guzman
    Boost.Spirit 、 Boost.Fusion 和 Boost.Phoneix 的作者。看過 Spirit 精妙的 C++ expression templates 魔術後,很難不對作者留下深刻印象。
  • Jeremy Siek
    六個 Boost libraries 的作者,很早就在 Boost 裡頭提供一套 concept check 的人。

嗯, Apple 這幾年應該算是最力挺 native code 的大型軟體公司(硬體公司?!),旗下的 LLVM、Clang 等 open source projects 不說,還雇用了 Doug Gregor (Modules for C++)、Howard Hinnant(libcxx 作者) 等神人在為更底層的基礎扎根,曾幾何時,竟然要喊聲: Apple 加油啊~

C++ Grandmaster Certification ( 一代宗師認證)

在 Ptt C_and_CPP 版看到網友的分享http://www.cppgm.org/index.html

是個免費的線上課程,但結業時要求妳/你寫出一套 C++ compiler (x86_64)、standard library、toolchain ,並且要符合 C++11 標準,過程中不可以使用任何的 3rd party code 。

Participants in this free online course will develop their own C++ compiler, standard library, and toolchain with the following features:

  • Compliant with the latest 2011 standard (C++11)
  • Written entirely in C++ with no third-party dependencies
  • Code generator targeting Linux x86_64
  • Full toolchain including preprocessor, assembler, and linker
  • Will build with itself (self-hosting) and pass provided conformance test suite

真是非常的硬!!!那過了,有什麼好處?目前網頁列出了三項:

  • the title Certified C++ Grandmaster [CPPGM]

CPPGM 認證過後的一代宗師!

  • a letter of recommendation detailing their achievement

CPPGM 會幫你寫一封介紹信!

  • access to a course graduate exclusive professional networking group

一代宗師網路俱樂部!

報名

2013/2/15: 報名截止

2013/3/1: 下一期開課

有興趣的趕快衝啊~不過認真一下,網路上 google 不太到 CPPGM 的詳細資訊,網頁上的自我介紹也很簡單幾句:

ABOUT CPPGM:

The CPPGM Foundation was formed by a software company that
recognized the value to programmer productivity that a good
knowledge of language mechanics had to new developers to
their team.  The C++ Grandmaster Certification began
development as an internal training program, and the
foundation was founded to offer it publicly.

 

或許是某個詐騙集團要騙 code 或是神奇企業的徵才方式?!不過若是能按部就班、完整提供這樣訓練內容的組織,大概也非等閒之輩,精通 C++11 標準、library 還有底層實務。衝著這些,報名去了~

WinDbg Tips: Automatically Break into the Target Computer

適用時機

  • 進行非常早期的 kernel debugging ,希望在 kernel 完成初始化後,立即中斷。
  • 追蹤 boot process 、kernel loader 、休眠啟動(resume from hibernation)。透過適當 BCDEdit 設定,也可用來 debug BootMgr, Winload.exe, WinResume.exe 等程式

說明

在 WinDbg 裡頭又稱作:Change Post-Reboot Break State 。目前共有三種模式可供切換:

No break
除非使用者按下 CTRL+Break 手動觸發一個 break event ,否則不會中斷 target 的運作。預設模式。
Break on reboot
當 target 上的 kernel 完成初始化後,立即中斷。 Break on first module load
當 target 上的 kernel 完成第一個 module 的載入,立即中斷。

語法

CTRL+ALT+K

範例

automatic break

應用

透過 BCDEdit 開啟 boot manager 的 debug :

bcdedit /set {bootmgr} bootdebug on

接著,在 WinDbg 中設定 Break on reboot ,重開機後,我們就可以看到 WinDbg 停在 bootmgr 上了。

bootmgr

感謝

會有這篇文章,是因為上了張銀奎老師的課,張銀奎老師不用多做介紹,他是软件调试[2]的作者,也常在高端调试[3]出沒(應該也是該網站的建立者?!),三天的課程非常精實,把 Windows Internals 用 WinDbg 方式再講一次,受益匪淺 :)

Reference

  1. CTRL+K (Change Post-Reboot Break State) (Windows Debuggers): http://msdn.microsoft.com/zh-tw/library/windows/hardware/ff540326%28v=vs.85%29.aspx
  2. 软件调试:http://advdbg.org/books/swdbg/
  3. 高端调试:http://advdbg.org/

Visual C++ Directories/Inherited Properties Changes

前言

在 Visual C++ 裡頭,C++ Directories 定義了 Visual C++ 這個 IDE 要去哪些路徑下找尋 header files/library files/sources files ,在 2005/2008 裡頭,全域的設定可以在 Tools > Options > Projects and Solutions > VC++ Directories 下找到。

image

圖一、VC++ 2005 下的 VC++ Directories Dialog

這個 dialog 在 VC++ 2010 不復存在了,取而代之的是請使用者使用 property sheet 以及 per-project 的設定。

image

如果好奇為什麼做了這樣的更動,可以參考 [2] 的文章,主要是因為:

  1. 這樣全域的設定太過強大,當使用者有許多 projects 在同一台機器上 build 時,容易混淆出錯。
  2. 因為這個全域的設定檔,是存放在 %LOCALAPPDATA%\Microsoft\VisualStudio\8.0\VCComponents.dat (8.0 為 VC++ 2005,9.0 則是 2008) 這個檔案裡頭,而不是跟著每個專案檔。因此當使用者使用 source control system 時,不會把設定跟著同步到 server 上,check-out 的人也因此無法正確建置專案了。
  3. VCComponents.dat 是給 VCBuild.exe 讀的 INI 檔,而 VC++ 2010 開始改用 MSBuild.exe 來作為統一的 build utility [3] ,因此竟然要改,就連同格式一起換掉吧。

按編:這三個理由實在都很說不過去,不過既然這是 Visual C++ team 的決定,我們也只能接受了 :~

UI 變動

從 2010 之後,變動後的 VC++ Directories 不再放在 Tools > Options > Projects and Solutions > VC++ Directories ,而是以 per-project 方式存在,使用者可以:

  • 對 project 按右鍵,選擇 properties > Configuration Properties > VC++ Directories
  • 或是,從工具列:Project > <your-project-name> properties > Configuration Properties > VC++ Directories

選取 VC++ Directories 。

image

很快地,妳/你會發現,新的 dialog 跟原有的沒什麼差別,而實際上也是,只是現在的變更都是 per-project 的,不再對所有的專案有效,因此若是妳/你想將 Boost library 作為所有 VC++ project 都會使用的函式庫,就沒辦法從這裡完成;也或是,妳/你更新了 Boost 版本,每個已經使用 Boost 又想升級的 projects ,就得手動來更改。

檔案位置與格式變化

說完了使用上的變動,接著是檔案位置的更動,存放的位置從:

%LOCALAPPDATA%\Microsoft\VisualStudio\8.0\VCComponents.dat

換到了:

%LOCALAPPDATA%\Microsoft\MSBuild\v4.0\

下,並且以 Microsoft.Cpp.<Platform>.user 命名:

  • Microsoft.Cpp.ARM.user
  • Microsoft.Cpp.Itanium.user
  • Microsoft.Cpp.Win32.user
  • Microsoft.Cpp.x64.user

image

新的檔案格式稱作:Property sheet ,附檔名 props 。有了這個檔案,我們還是有機會可以做到 2005 & 2008 時的全域設定。先前提到了:為了迎接 MSBuild 的來臨,VC++ 將 INI 格式變成了 XML 格式,所以客製化上還是很簡單的,任選一個 platform 的檔案打開:

image

所以一種修改方式,就是直接用編輯器修改 XML ,看想修改哪些就可以改,值得一提的是,以往在 2005 & 2008 裡頭,路徑名不可以是 Visual C++ 裡頭的 Macro ,現在反倒是可以了,因為 IDE 是將檔案中的值讀入後才做解析。另外一種方式則是透過 Visual C++ 內建的 Property Manager 修改,我們放到下一節介紹。

Inherited Values

wdk803

當 Visual C++ 將 property sheet 讀入後,會當做 Inherited values ,對於當前 project 來說,是不可編輯的,我們必須繞到 props 檔去,或是使用 property manager 編輯。property manager 可以從工具列 > View > Property Manager 找到:

image

叫起 Property Manager 後,可以看到目前 project configuration 所涵蓋的 platform 的設定。 Double click 後,可以看到跳出一個視窗,

image

跳出來的視窗長得很像 project properties ,不過仔細看會發現 Configuration 和 Platform 已經被鎖死成對應的 property sheet 檔所代表的設定,接著,直接編輯,然後存檔,這樣就完成了修改全域 property sheet 了。

VC++ 2010 & VC++2012

值得注意的是,property sheet 放在 MSBuild 的 local app data 下,而目前 2010 和 2012 所使用的 MSBuild 都是 4.0 [4],因此一旦我們修改了 property sheet ,可是會同時影響到 2010 跟 2012 的 ... Orz ...

Reference

  1. Inherited Properties and Property Sheets: http://blogs.msdn.com/b/vsproject/archive/2009/06/23/inherited-properties-and-property-sheets.aspx
  2. VC++ Directories: http://blogs.msdn.com/b/vsproject/archive/2009/07/07/vc-directories.aspx
  3. VCBuild vs. C++ MSBuild on the Command Line: http://blogs.msdn.com/b/vcblog/archive/2010/01/11/vcbuild-vs-c-msbuild-on-the-command-line.aspx
  4. MSBuild Toolset: http://msdn.microsoft.com/en-us/library/bb383796.aspx

VC++ 2012 Can't Build Driver Project

這幾天終於趁著聽課的空檔,把電腦裝了 VC++ 2012 ,這版的一大特色:整合了 device driver 的開發。很快地試玩了一下它的 project wizard :

wdk801

結果,很不幸地失敗 ...

1>C:\Program Files (x86)\Windows Kits\8.0\Include\KM\wdm.h(10920): fatal error C1003: error count exceeds 100; stopping compilation

再看一下 Error list:

Error    1    error C2220: warning treated as error - no 'object' file generated    C:\Program Files (x86)\Windows Kits\8.0\Include\shared\sal.h    2884
Error    4    error C2054: expected '(' to follow '_IRQL_requires_same_'    C:\Program Files (x86)\Windows Kits\8.0\Include\shared\ntdef.h    1897
Error    5    error C2085: 'EXCEPTION_ROUTINE' : not in formal parameter list    C:\Program Files (x86)\Windows Kits\8.0\Include\shared\ntdef.h    1903
Error    6    error C2085: 'EXCEPTION_ROUTINE' : not in formal parameter list    C:\Program Files (x86)\Windows Kits\8.0\Include\shared\ntdef.h    1905
Error    7    error C2143: syntax error : missing ';' before '*'    C:\Program Files (x86)\Windows Kits\8.0\Include\shared\ntdef.h    1905
Error    8    error C2143: syntax error : missing ')' before 'constant'    C:\Program Files (x86)\Windows Kits\8.0\Include\KM\wdm.h    10384
Error    9    error C2143: syntax error : missing '{' before 'constant'    C:\Program Files (x86)\Windows Kits\8.0\Include\KM\wdm.h    10384
Error    10    error C2059: syntax error : '<Unknown>'    C:\Program Files (x86)\Windows Kits\8.0\Include\KM\wdm.h    10384

真的是很 ooxx 。問題都是發生在 sal.h, ntdef.h wdm.h 等等基本的 header files 裡。

這類的問題通常是發生在 include 了錯誤的 header files ,所以回頭檢視 solution property : Project >  Properties > Configuration Properties > VC++ Directories 。

image

include directories 多了很多路徑,其他像是 Executable Directories 、Library Directories 也有一樣的問題。嗯嗯,VC++ 2012 匯入了電腦上其他版本 VC++ 的設定,可能的原因之一:安裝完 2012 、第一次啟動時,我允許了 2012 去找尋舊版本的設定並匯入所導致。再點開 Include Directories 看一下:

image

發現這些多餘的路徑都是來自 Inherited values 。這裡,我試了兩種解決方式:

  1. 解法一
    取消 Inherit from parent or project defaults ,然後重新把需要的路徑一個一個加回去,也就是手動把
    $(ProjectDir)、$(CRT_INC_PATH)、$(ddk_INC_PATH)、$(KIT_SHARED_INC_PATH) 加上去。手動作這件事除了麻煩外,還只能用在這個 project 上,也就是一旦我開了新的 driver solution 或是在當下 solution 下新增新的 driver project 都得重做一次。
  2. 解法二
    比較一勞永逸, VC++ 把這個 Inherited Values 定義在 C:\Users\<user-name>\AppData\Local\Microsoft\MSBuild\v4.0 下的檔案裡頭,檔案是根據不同 configuration 而命名:
    Microsoft.Cpp.ARM.user.props
    Microsoft.Cpp.Itanium.user.props
    Microsoft.Cpp.Win32.user.props
    Microsoft.Cpp.x64.user.props
    *.props 是 XML 格式,把不用的 path 都清除乾淨,只留下 default value 就可以了。
    <?xml version="1.0" encoding="utf-8"?>
    <Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
      <PropertyGroup>
        <ExecutablePath>$(ExecutablePath)</ExecutablePath>
        <IncludePath>$(IncludePath)</IncludePath>
        <ReferencePath>$(ReferencePath)</ReferencePath>
        <LibraryPath>$(LibraryPath)</LibraryPath>
        <SourcePath>$(SourcePath)</SourcePath>
        <ExcludePath>$(ExcludePath)</ExcludePath>
      </PropertyGroup>
    </Project>

    這個方法是比較一勞永逸,不過有個大缺點:不同版本的 Visual C++ 會共用這個檔案。像我的電腦修改了後, VC++ 2010 的 VC++ project 的預設值也會受到影響,但已經產生的、既有 project 則不受影響,算是不幸中的大幸。

Facebook App -- Getting Started with Apps on Facebook + Heroku

Facebook App 時下分成三類:

  1. Facebook for Websites
    這類的 apps ,可以讓妳/你使用 Facebook 提供的 social plugins 來幫自己的網站加分,像是在你的網頁中加入"讚"按鈕、讓使用者使用 Facebook 帳號登入、存取使用者在 Facebook 的資料。
  2. Mobile Apps
    Facebook 分別在 iOS 和 Android 上提供 Object-C 和 Java 版本的 SDK ,來讓開發者可以提供 native apps。其他還有 PHP 和 JavaScript 可以選擇。
  3. Apps on Facebook
    把我們的 apps 整合在 Facebook 上,使用者必須透過 Facebook 來存取我們的 apps , Facebook 提供適當的頁面,並把我們的 apps 導入其中的 iframe 裡頭。

特別要注意的是, Facebook 只提供我們使用 Facebook 的 social platform ,但它並不提供 code hosting ,因此開發 Apps on Facebook 需要自己準備 web server 或是第三方的 web hosting ,運氣不錯的是,Facebook 和 Heroku 有正式的合作,因此若是找不到代管服務或是懶得自己架站的開發者,可以先使用 Heroku 來試試看。

Apps on Facebook

步驟一

登入 https://developers.facebook.com/apps 。第一次登入時, Facebook 會詢問您相關的 permission ,選 allow 就可以。之後就會看到下面的畫面,點選 Create New App

FB_App_1

步驟二

image

  • App Name: 輸入妳/你的 app name 。
  • App Namespace: 其實就是我們 app 的 URL 。它會附加在 http://apps.facebook.com 之後,所以必須是個 unique name ,另外還有一些名規則。 輸入完後 Dialog 會幫你 check ,若是失敗也會報錯。
  • Web Hosting: 目前 Facebook 只跟 Heroku 官方合作,所以要是我們沒有自己的 hosting server ,也可以考慮一下 Heroku ,它支援 PHP 、 Python 、 JavaScript 、 Ruby 。

步驟三

跟 Facebook 說一下,妳/你不是機器人吧~

步驟四

image

選擇一下妳/你想用的開發語言。

image

若是事先沒有 Heroku 帳號也不用擔心,透過這個步驟填入 email 就會幫妳/你申請。

步驟五

image

看到這個 dialog 出現,就恭喜妳/你成功囉。

步驟六

當妳/你點下 Go To App 後,瀏覽頁會被導到 Heroku 代管的 app page 去,以這邊的例子會是:http://evening-plateau-9255.herokuapp.com

FB_App_3

開發

步驟一、找到對應的 Git repository

若是之前沒有 Heroku 的帳號,當完成上面的步驟後,Heroku 會寄一封啟動信到步驟四的信箱去。或是之前已經有 Heroku 帳號,可以直接到 https://dashboard.heroku.com/apps? 去看一下,會發現多了一個 evening-plateau-9255 ,點進去後,請找 Settings > Info > Git URL ,以本文的例子, Heroku 配給我們的 git url 是 git@heroku.com:evening-plateau-9255.git

步驟二、下載 Herolu toolbelt

toolbelt 是 cmd line 工具包,主要包含了 Heroku 環境初始化工具、app 的 local 模擬和 Git 。

步驟三、初始化環境

安裝完 toolbelt 後,它應該已經被加入到環境變數裡頭。這時,請準備一個新資料夾來當做 working folder ,並使用 cmd.exe 切到該 folder 下,執行:

heroku login

image

步驟四、Clone 一份來改吧

還記得自己的 app git URL 嗎?

git clone git@heroku.com:your_app_name_in_heroku.git -o heroku

到這裡,妳/你已經可以開始做些了,若是不熟悉 Git ,可以參考下面指令把你的修改上傳到 server 上去:

git commit -am "commit message"
git push heroku master

Reference

  1. Canvas Tutorial: http://developers.facebook.com/docs/appsonfacebook/tutorial/
  2. Getting Started with Your Facebook App on Heroku: https://devcenter.heroku.com/articles/facebook

Windows Debugging 2 – Kernel Debugging with WinDbg and VMware

Windows Vista 之後已經不再將開機選項儲存於 boot.ini 中,而是改以 BCD (Boot Configuration Data) 儲存,因此以前透過編輯 boot.ini 啟動 Windows kernel debugging 的方法也得更新一下。這裡我們透過 bcdedit.exe 來編輯 BCD ,讓 Windows 啟動後可以進入 debug mode 。

VMware 設定

Debuggee 部分,和以前一樣使用 named piped 來替 guest OS 模擬 serial port (COM port)。

  1. 進入 guest OS 設定。 com port
  2. 新增硬體。
    com port 2
  3. 選擇 Serial Port 裝置。
    com port 3
  4. 選擇 named pipe 來模擬我們的 serial port。
    com port 4
  5. 替 named pipe 取一個名字,這個名字等會會被 WinDbg 使用。
    com port 5
  6. 最後別忘了把 Yield CPU on Poll 選項勾起。
    com port 6
  7. 完成新增後,請留意 VMware 替我們新增的 Serial Port 的編號,以上圖為例是:Serial Port 2 

Windows Boot 設定

  1. 使用 administrator 權限開啟一個 cmd。
    start cmd
  2. 透過 BCDEdit 編輯開機選項,使用 COM port (serial port)來做為 debugger 和 debuggee 間的溝通,debugport 的編號請根據 VMware 的 Serial Port 設定而定:
    bcdedit /dbgsettings serial debugport:2
  3. 複製現有的開機選項到 DebugEntr:
    bcdedit /copy {current} /d DebugEntry
    執行完該指令後,會出現一個 ID ,代表我們要複製出來的開機選項,該 ID 在每台電腦上都不太一樣。
  4. 調整開機選樣的順序:
    bcdedit /displayorder {current} {ID}
  5. 打開 debug 選項:
    bcdedit /debug {ID} ON
  6. 設定成預設開機選項:
    bcdedit /default {ID}
    bcdedit edit

 

Enable Debug Print

Vista之後,DbgPrintEx()、vDbgPrintEx()、vDbgPrintExWithPrefix()、KdPrintEx() 等選擇性的輸出函式預設是關閉的,要啟動的話,需要到 registry 上設定對應的 log level [3]:

到 HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Debug Print Filter 下新增 DEFAULT=dword:0000ffff
實際數值,依照需求而定,0000ffff 足以應付大多數用途。

Debug Print Filter

使用

在 bcdedit 設定完成後,重開機,便會看到新的開機選項 DebugEntry:

boot 1

選擇 DebugEntry 後,我們便可以在 debugger 的機器上的 cmd 執行下面指令來進行 kernel debugging,com_1 就是我們當初在 VMware guest OS 裡頭設定的名字:

windbg -b -k com:pipe,port=\\.\pipe\com_1,resets=0

停用驅動程式簽章增強(Disable Driver Signature Enforcement)

Vista 之後的 64-bit OS ,Microsoft 都會要求 drivers 必須有 WHQL 的認證才能啟動。這對於一般使用者來說可能沒有影響,但對於有在開發、測試 drivers 的人就會是個問題。

最簡單的方式是,開機時,使用 F8 進入進階模式:
boot 1
並選擇(停用驅動程式簽章增強)Disable Driver Signature Enforcement。
boot 2

Test Signing

若是 drivers 有 test sign ,那麼我們還可以使用 BCDEdit 來允許 testing sign driver 的載入[4]:
bcdedit /set TESTSIGNING ON
設定完成後,需要重開機。

要驗證 test sign 是否成功,可以使用 bcdedit 檢查,或是觀察桌面右下角的文字說明:

test signing

Reference

  1. Boot Parameters to Enable Debugging
    http://msdn.microsoft.com/en-us/library/windows/hardware/ff542279%28v=vs.85%29.aspx
  2. Kernel Debugging in Windows Vista
    http://msdn.microsoft.com/en-us/windows/hardware/gg487520
  3. Reading and Filtering Debugging Messages
    http://msdn.microsoft.com/en-us/library/windows/hardware/ff551519%28v=vs.85%29.aspx
  4. The TESTSIGNING Boot Configuration Option
    http://msdn.microsoft.com/en-us/library/windows/hardware/ff553484%28v=vs.85%29.aspx

See Also

  1. Windows Debugging – Kernel Debugging with WinDbg and VMware
    http://keikoblog.blogspot.com/2009/03/windows-debugging-kernel-debugging-with.html

MiniFilter InstanceSetupCallback is not called?

一般來說,MiniFilter 的 InstanceSetupCallback 會在 filter manager 把 minifilter attache 到 volume 後呼叫。如果沒有的話,可以檢查一下 minifilter 的 INF 是否把 instance fla...