這是標題
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.
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 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
}
...
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_CHECK_EXCEPTION(
p.parseString("---\n---"),
durin::yaml::ParserException,
[]( const durin::yaml::ParserException& ex ) {
return ex.what() == std::string( "Double DocBegin" );
});
Feel so sad ...
奇怪,今天嘗試在 vscode 中使用 lldb live debug 一個 C++ 程式,斷點下好後卻卡住了。
Console 的錯誤訊息是:bind: Invalid command `enable-meta-key’.
上網查了一下,貌似 vscode、 QtCreator 都有災情。
追了一下才發現,自己的環境有兩份 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"
}
kde neon 上的 vscode 貌似在自動更新後,native menu bar 的字體顏色變得跟 native theme 的顏色太接近,人眼幾乎沒辦法看出字來。
調整了一下系統的 theme或是調整 dark mode 都沒有用。好在 menu bar 可以改成 vscode 自己畫。
Chandler Caruth 在 GoingNative 2013 上宣布了一個好消息,LLVM 3.4 (開發中)正在如火如荼地移植到 Windows 上,目前初步的成果已經可以使用 Visual Studio 2010/2012 作為 IDE 了,對於習慣 Visual Studio 的人來講應該是個好消息。
alpha 版本可以在這邊下載到:
試玩了一下發現:
C# + .NET framework 2.0 + Visual Studio 2010 + remote debugging = 殘廢
C# + .NET framework 2.0 + dump + WinDbg = 悲劇
讓我想起了以前微軟研究院利用 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
在 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 上有他們的黃金陣容的介紹:
嗯, Apple 這幾年應該算是最力挺 native code 的大型軟體公司(硬體公司?!),旗下的 LLVM、Clang 等 open source projects 不說,還雇用了 Doug Gregor (Modules for C++)、Howard Hinnant(libcxx 作者) 等神人在為更底層的基礎扎根,曾幾何時,竟然要喊聲: Apple 加油啊~
在 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
真是非常的硬!!!那過了,有什麼好處?目前網頁列出了三項:
CPPGM 認證過後的一代宗師!
CPPGM 會幫你寫一封介紹信!
一代宗師網路俱樂部!
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 裡頭又稱作:Change Post-Reboot Break State 。目前共有三種模式可供切換:
CTRL+ALT+K
透過 BCDEdit 開啟 boot manager 的 debug :
bcdedit /set {bootmgr} bootdebug on
接著,在 WinDbg 中設定 Break on reboot ,重開機後,我們就可以看到 WinDbg 停在 bootmgr 上了。
會有這篇文章,是因為上了張銀奎老師的課,張銀奎老師不用多做介紹,他是软件调试[2]的作者,也常在高端调试[3]出沒(應該也是該網站的建立者?!),三天的課程非常精實,把 Windows Internals 用 WinDbg 方式再講一次,受益匪淺 :)
在 Visual C++ 裡頭,C++ Directories 定義了 Visual C++ 這個 IDE 要去哪些路徑下找尋 header files/library files/sources files ,在 2005/2008 裡頭,全域的設定可以在 Tools > Options > Projects and Solutions > VC++ Directories 下找到。
圖一、VC++ 2005 下的 VC++ Directories Dialog
這個 dialog 在 VC++ 2010 不復存在了,取而代之的是請使用者使用 property sheet 以及 per-project 的設定。
如果好奇為什麼做了這樣的更動,可以參考 [2] 的文章,主要是因為:
按編:這三個理由實在都很說不過去,不過既然這是 Visual C++ team 的決定,我們也只能接受了 :~
從 2010 之後,變動後的 VC++ Directories 不再放在 Tools > Options > Projects and Solutions > VC++ Directories ,而是以 per-project 方式存在,使用者可以:
選取 VC++ Directories 。
很快地,妳/你會發現,新的 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 命名:
新的檔案格式稱作:Property sheet ,附檔名 props 。有了這個檔案,我們還是有機會可以做到 2005 & 2008 時的全域設定。先前提到了:為了迎接 MSBuild 的來臨,VC++ 將 INI 格式變成了 XML 格式,所以客製化上還是很簡單的,任選一個 platform 的檔案打開:
所以一種修改方式,就是直接用編輯器修改 XML ,看想修改哪些就可以改,值得一提的是,以往在 2005 & 2008 裡頭,路徑名不可以是 Visual C++ 裡頭的 Macro ,現在反倒是可以了,因為 IDE 是將檔案中的值讀入後才做解析。另外一種方式則是透過 Visual C++ 內建的 Property Manager 修改,我們放到下一節介紹。
當 Visual C++ 將 property sheet 讀入後,會當做 Inherited values ,對於當前 project 來說,是不可編輯的,我們必須繞到 props 檔去,或是使用 property manager 編輯。property manager 可以從工具列 > View > Property Manager 找到:
叫起 Property Manager 後,可以看到目前 project configuration 所涵蓋的 platform 的設定。 Double click 後,可以看到跳出一個視窗,
跳出來的視窗長得很像 project properties ,不過仔細看會發現 Configuration 和 Platform 已經被鎖死成對應的 property sheet 檔所代表的設定,接著,直接編輯,然後存檔,這樣就完成了修改全域 property sheet 了。
值得注意的是,property sheet 放在 MSBuild 的 local app data 下,而目前 2010 和 2012 所使用的 MSBuild 都是 4.0 [4],因此一旦我們修改了 property sheet ,可是會同時影響到 2010 跟 2012 的 ... Orz ...
這幾天終於趁著聽課的空檔,把電腦裝了 VC++ 2012 ,這版的一大特色:整合了 device driver 的開發。很快地試玩了一下它的 project wizard :
結果,很不幸地失敗 ...
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 。
include directories 多了很多路徑,其他像是 Executable Directories 、Library Directories 也有一樣的問題。嗯嗯,VC++ 2012 匯入了電腦上其他版本 VC++ 的設定,可能的原因之一:安裝完 2012 、第一次啟動時,我允許了 2012 去找尋舊版本的設定並匯入所導致。再點開 Include Directories 看一下:
發現這些多餘的路徑都是來自 Inherited values 。這裡,我試了兩種解決方式:
<?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>
Facebook App 時下分成三類:
特別要注意的是, Facebook 只提供我們使用 Facebook 的 social platform ,但它並不提供 code hosting ,因此開發 Apps on Facebook 需要自己準備 web server 或是第三方的 web hosting ,運氣不錯的是,Facebook 和 Heroku 有正式的合作,因此若是找不到代管服務或是懶得自己架站的開發者,可以先使用 Heroku 來試試看。
登入 https://developers.facebook.com/apps 。第一次登入時, Facebook 會詢問您相關的 permission ,選 allow 就可以。之後就會看到下面的畫面,點選 Create New App
跟 Facebook 說一下,妳/你不是機器人吧~
選擇一下妳/你想用的開發語言。
若是事先沒有 Heroku 帳號也不用擔心,透過這個步驟填入 email 就會幫妳/你申請。
看到這個 dialog 出現,就恭喜妳/你成功囉。
當妳/你點下 Go To App 後,瀏覽頁會被導到 Heroku 代管的 app page 去,以這邊的例子會是:http://evening-plateau-9255.herokuapp.com
若是之前沒有 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 toolbelttoolbelt 是 cmd line 工具包,主要包含了 Heroku 環境初始化工具、app 的 local 模擬和 Git 。
安裝完 toolbelt 後,它應該已經被加入到環境變數裡頭。這時,請準備一個新資料夾來當做 working folder ,並使用 cmd.exe 切到該 folder 下,執行:
heroku login
步驟四、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
Windows Vista 之後已經不再將開機選項儲存於 boot.ini 中,而是改以 BCD (Boot Configuration Data) 儲存,因此以前透過編輯 boot.ini 啟動 Windows kernel debugging 的方法也得更新一下。這裡我們透過 bcdedit.exe 來編輯 BCD ,讓 Windows 啟動後可以進入 debug mode 。
Debuggee 部分,和以前一樣使用 named piped 來替 guest OS 模擬 serial port (COM port)。
bcdedit /dbgsettings serial debugport:2
bcdedit /copy {current} /d DebugEntry
執行完該指令後,會出現一個 ID ,代表我們要複製出來的開機選項,該 ID 在每台電腦上都不太一樣。bcdedit /displayorder {current} {ID}
bcdedit /debug {ID} ON
Vista之後,DbgPrintEx()、vDbgPrintEx()、vDbgPrintExWithPrefix()、KdPrintEx() 等選擇性的輸出函式預設是關閉的,要啟動的話,需要到 registry 上設定對應的 log level [3]:
到 HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Debug Print Filter 下新增 DEFAULT=dword:0000ffff
實際數值,依照需求而定,0000ffff 足以應付大多數用途。
在 bcdedit 設定完成後,重開機,便會看到新的開機選項 DebugEntry:
選擇 DebugEntry 後,我們便可以在 debugger 的機器上的 cmd 執行下面指令來進行 kernel debugging,com_1 就是我們當初在 VMware guest OS 裡頭設定的名字:
windbg -b -k com:pipe,port=\\.\pipe\com_1,resets=0
Vista 之後的 64-bit OS ,Microsoft 都會要求 drivers 必須有 WHQL 的認證才能啟動。這對於一般使用者來說可能沒有影響,但對於有在開發、測試 drivers 的人就會是個問題。
最簡單的方式是,開機時,使用 F8 進入進階模式:
並選擇(停用驅動程式簽章增強)Disable Driver Signature Enforcement。
若是 drivers 有 test sign ,那麼我們還可以使用 BCDEdit 來允許 testing sign driver 的載入[4]:
bcdedit /set TESTSIGNING ON
設定完成後,需要重開機。
要驗證 test sign 是否成功,可以使用 bcdedit 檢查,或是觀察桌面右下角的文字說明:
一般來說,MiniFilter 的 InstanceSetupCallback 會在 filter manager 把 minifilter attache 到 volume 後呼叫。如果沒有的話,可以檢查一下 minifilter 的 INF 是否把 instance fla...