-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathatom.xml
138 lines (80 loc) · 43.8 KB
/
atom.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>M_Kepler</title>
<link href="/atom.xml" rel="self"/>
<link href="http://yoursite.com/"/>
<updated>2020-04-18T18:30:46.314Z</updated>
<id>http://yoursite.com/</id>
<author>
<name>M_Kepler</name>
</author>
<generator uri="http://hexo.io/">Hexo</generator>
<entry>
<title>vscode 远程开发</title>
<link href="http://yoursite.com/2019/07/14/vscode%E8%BF%9C%E7%A8%8B%E5%BC%80%E5%8F%91/"/>
<id>http://yoursite.com/2019/07/14/vscode远程开发/</id>
<published>2019-07-14T03:38:20.223Z</published>
<updated>2020-04-18T18:30:46.314Z</updated>
<content type="html"><![CDATA[<!-- TOC --><ul><li><a href="#场景描述">场景描述</a></li><li><a href="#解决方案">解决方案</a><ul><li><a href="#remote-ssh"><code>REMOTE-SSH</code></a></li><li><a href="#remote-vscode"><code>REMOTE VSCODE</code></a></li><li><a href="#sftp-⭐"><code>SFTP</code> ⭐</a></li></ul></li></ul><!-- /TOC --><h1 id="场景描述"><a href="#场景描述" class="headerlink" title="场景描述"></a>场景描述</h1><ul><li><p><code>Windows</code> 下用 <code>vscode</code> 进行开发</p></li><li><p><code>Linux</code> 服务器的内核被精简过,而且无法直接连接外网下载安装其他软件,只能从虚拟桌面下载后拷贝到服务器上进行离线安装</p></li><li><p>项目在远程服务器上,源代码的目录结构与安装部署之后的目录结构差异很大,比如 <code>B</code> 目录在源码中是 <code>A</code> 的子目录,但是安装之后 <code>B</code> 目录的文件将被移动到其他地方,库代码会安装到第三方库路径<code>/usr/lib/python2.7/site-packages/xx</code>下,有的代码会放到 <code>www/xxx cgi</code> 对应的路径下。因此在本地开发后拷贝到服务器上还要找对路径</p></li><li><p>如果是在本地编辑,编辑之后拷贝到服务器上运行,有时候需要修改的代码只有一点点,又迫切想看到效果,就会直接在服务器上进行修改,很容易出现单边问题</p></li></ul><h1 id="解决方案"><a href="#解决方案" class="headerlink" title="解决方案"></a>解决方案</h1><h2 id="REMOTE-SSH"><a href="#REMOTE-SSH" class="headerlink" title="REMOTE-SSH"></a><code>REMOTE-SSH</code></h2><ul><li><p>下载安装好 <code>remote-ssh</code></p></li><li><p>微软发布的远程开发工具套件中的一个,不幸的是这个插件连接服务器后会自动在服务器上下载安装 <code>.vscode-server</code>,但是我们的服务器是无法连接外网的,所以下载失败。</p></li><li><p>把 <code>vscode</code> 的输出打开,可以看到执行哪个脚本失败,找到这个安装脚本 <code>vscode-remote-install.xxxxx.sh</code>,手动执行里面的代码,在下载 <code>.vscode-server</code>的时候出错,手动通过虚拟桌面把这个文件下载下来,链接如下:</p><figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 自行将 $COMMIT_ID 替换成 上面得到的数值</span></span><br><span class="line">https://update.code.visualstudio.com/commit:<span class="variable">$COMMIT_ID</span>/server-linux-x64/insider</span><br></pre></td></tr></table></figure></li><li><p>下载完放到服务器 <code>$HOME</code> 目录下后,接着执行脚本中剩下的步骤,最终目录如下</p><figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">.vscode-server/</span><br><span class="line">├── bin</span><br><span class="line">│ └── xxxxx</span><br><span class="line">├── data</span><br><span class="line">│ ├── logs</span><br><span class="line">│ ├── Machine</span><br><span class="line">│ ├── machineid</span><br><span class="line">│ └── User</span><br><span class="line">└── extensions</span><br><span class="line"> └── ms-python.python-2019.5.18875</span><br></pre></td></tr></table></figure></li><li><p>好了,离线安装上了,应该可以正常链接了吧,通过 <code>vscode</code> 去链接远程服务器,发现报错 <code>g++</code> 版本不对,因为这台服务器的内核被精简过,很多软件包都缺失,离线安装新版本太痛苦;而且新的 <code>g++</code> 又可能因为版本不对导致项目运行不起来</p></li><li><p>因此,该方案不可行<br>如果能装上还是很不错的,装上之后在 <code>vscode</code> 可以直接检索打开远程机器上的文件夹,就像在本地开发一样。</p></li></ul><h2 id="REMOTE-VSCODE"><a href="#REMOTE-VSCODE" class="headerlink" title="REMOTE VSCODE"></a><code>REMOTE VSCODE</code></h2><ul><li><p><a href="https://www.cnblogs.com/learn21cn/p/6189023.html" target="_blank" rel="noopener">安装使用过程</a></p></li><li><p>缺点</p><ul><li>每次使用都需要先在本地执行一下 <code>ssh -R 52698:127.0.0.1:52698 [email protected]</code></li><li>远程机器上打开文件时需要指定端口 <code>rmate -p 52698 linux中的文件名称</code>,可以通过 <code>alias</code> 解决</li><li>只能编辑单个文件</li></ul></li><li><p>优点<br>编辑单个文件很方便,在<code>当前路径下的文件</code>可以直接在 <code>vscode</code> 上打开该文件,而不像 <code>sftp</code> 要慢慢找到路径再打开文件编辑</p></li></ul><h2 id="SFTP-⭐"><a href="#SFTP-⭐" class="headerlink" title="SFTP ⭐"></a><code>SFTP</code> ⭐</h2><blockquote><p>最终解决方案<br>在服务器上对应的文件夹下创建软链就 <code>ok</code> 了,比如安装后是在 <code>site-packages</code> 下,但是可以把代码上传到 <code>/root/source/</code> 然后创建一个软链到 <code>site-packages</code></p></blockquote><ul><li><p>插件配置 <code>sftp.json</code></p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line">{</span><br><span class="line"> <span class="string">"name"</span>: <span class="string">"xxx"</span>,</span><br><span class="line"> <span class="string">"host"</span>: <span class="string">"xxx.xxx.xxx.xxx"</span>, <span class="comment">// 服务器IP</span></span><br><span class="line"> <span class="string">"protocol"</span>: <span class="string">"sftp"</span>,</span><br><span class="line"> <span class="string">"port"</span>: <span class="number">22</span>,</span><br><span class="line"> <span class="string">"username"</span>: <span class="string">"root"</span>, <span class="comment">// 登录用户名</span></span><br><span class="line"> <span class="string">"password"</span>: <span class="string">"xxxxxxxx"</span>, <span class="comment">// 登录密码</span></span><br><span class="line"> <span class="comment">// 在工作空间的文件夹上右键上传,就会把文件上传到以下路径</span></span><br><span class="line"> <span class="comment">// 如果源代码目录结构为 /A/B/xxx 而.vscode与B是【同级目录】</span></span><br><span class="line"> <span class="comment">// 上传后远程服务器路径为 /root/source/B/xxx</span></span><br><span class="line"> <span class="string">"remotePath"</span>: <span class="string">"/root/source"</span>,</span><br><span class="line"> <span class="string">"uploadOnSave"</span>: <span class="literal">false</span>,</span><br><span class="line"> <span class="string">"downloadOnOpen"</span>: <span class="literal">false</span>,</span><br><span class="line"> <span class="string">"ignore"</span>: [</span><br><span class="line"> <span class="string">".vscode"</span>,</span><br><span class="line"> <span class="string">".git"</span>,</span><br><span class="line"> <span class="string">".DS_Store"</span></span><br><span class="line"> ]</span><br><span class="line">}</span><br></pre></td></tr></table></figure></li><li><p>创建软链</p><figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 库</span></span><br><span class="line"><span class="built_in">cd</span> /usr/lib/python2.7/site-packages/</span><br><span class="line">ln -s /root/<span class="built_in">source</span>/B/xxx/lib/python/xxxlib</span><br><span class="line"></span><br><span class="line"><span class="comment"># 如果 xxxlib 中还包含其他目录的代码,也一样创建软链到xxxlib下就可以了</span></span><br><span class="line"><span class="built_in">cd</span> /root/<span class="built_in">source</span>/B/xxx/lib/python/xxxlib</span><br><span class="line">ln -s /root/<span class="built_in">source</span>/B/<span class="built_in">source</span>/src/daemon/xxxx</span><br></pre></td></tr></table></figure></li><li><p>配置之后就可以愉快地在本地打开源代码进行编辑,编辑完成之后右键<code>UPLOAD</code>就可以替换上去了,当然也可以设置本地保存立即上传,最关键的是通过 <code>软链</code> 来解决了项目代码结构和服务器代码结构不一致的问题</p></li></ul>]]></content>
<summary type="html">
<!-- TOC -->
<ul>
<li><a href="#场景描述">场景描述</a></li>
<li><a href="#解决方案">解决方案</a><ul>
<li><a href="#remote-ssh"><code>REMOTE-SSH</code></a></
</summary>
<category term="开发环境" scheme="http://yoursite.com/categories/%E5%BC%80%E5%8F%91%E7%8E%AF%E5%A2%83/"/>
<category term="vscode" scheme="http://yoursite.com/tags/vscode/"/>
<category term="python" scheme="http://yoursite.com/tags/python/"/>
</entry>
<entry>
<title>vscode+wsl搭建go和c++开发环境</title>
<link href="http://yoursite.com/2019/04/17/vscode+wsl%E6%90%AD%E5%BB%BAgo%E5%92%8Cc++%E5%BC%80%E5%8F%91%E7%8E%AF%E5%A2%83/"/>
<id>http://yoursite.com/2019/04/17/vscode+wsl搭建go和c++开发环境/</id>
<published>2019-04-17T08:05:28.825Z</published>
<updated>2020-04-18T18:22:03.743Z</updated>
<content type="html"><![CDATA[<!-- TOC --><ul><li><a href="#使用场景">使用场景</a></li><li><a href="#操作步骤">操作步骤</a><ul><li><a href="#开启-wsl并配置为-vscode-默认终端">开启 <code>wsl</code>,并配置为 <code>vscode</code> 默认终端</a></li><li><a href="#通过-bat-执行-bash-命令">通过 <code>bat</code> 执行 <code>bash</code> 命令</a></li><li><a href="#taskjson"><code>task.json</code></a></li><li><a href="#launchjson"><code>launch.json</code></a></li></ul></li><li><a href="#使用说明">使用说明</a><ul><li><a href="#make-工程"><code>make</code> 工程</a></li><li><a href="#配置-go">配置 <code>go</code></a></li></ul></li></ul><!-- /TOC --><h1 id="使用场景"><a href="#使用场景" class="headerlink" title="使用场景"></a>使用场景</h1><p>借助 <code>wsl</code> 在 <code>windows</code> 下进行 <code>linux</code> 环境开发</p><h1 id="操作步骤"><a href="#操作步骤" class="headerlink" title="操作步骤"></a>操作步骤</h1><h2 id="开启-wsl,并配置为-vscode-默认终端"><a href="#开启-wsl,并配置为-vscode-默认终端" class="headerlink" title="开启 wsl,并配置为 vscode 默认终端"></a>开启 <code>wsl</code>,并配置为 <code>vscode</code> 默认终端</h2><ul><li><a href="https://www.jianshu.com/p/3e627ff45ccb" target="_blank" rel="noopener">网上很多方法,这里不赘述</a></li></ul><h2 id="通过-bat-执行-bash-命令"><a href="#通过-bat-执行-bash-命令" class="headerlink" title="通过 bat 执行 bash 命令"></a>通过 <code>bat</code> 执行 <code>bash</code> 命令</h2><ul><li><p>装上 <code>WSL</code> 后,可以在 <code>bash</code> 下执行命令,但是如果想在 <code>windows</code> 系统下做开发的话,不能直接执行 <code>bash</code> 命令</p></li><li><p>可以通过 <code>cmd</code> 批处理命令来调用 <code>bash</code> 并执行 <code>shell</code> 命令,使用方法如下:</p><figure class="highlight bat"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="function">C:\<span class="title">Users</span>\<span class="title">User_Name</span>><span class="title">bash</span> -<span class="title">c</span> " <span class="title">ls</span> ~/"</span></span><br></pre></td></tr></table></figure></li><li><p>写个批处理命令,来实现 <code>windows</code> 下用 <code>vscode</code> 写代码,然后在 <code>wsl</code> 下编译运行代码,这里路径有个问题,<code>windows</code>下路径是右斜杠,而<code>linux</code>下是左斜杠,所以利用批处理把右斜杠替换成左斜杠</p><figure class="highlight bat"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">set</span> cpp_path=%<span class="number">1</span></span><br><span class="line"><span class="built_in">set</span> "cpp_path=<span class="variable">%cpp_path:\=/%</span>"</span><br><span class="line">bash -c "rm -f %<span class="number">2</span> && g++ --std=c++<span class="number">11</span> -g <span class="variable">%cpp_path%</span> -o %<span class="number">2</span> -lpthread && clear && <span class="built_in">time</span> %<span class="number">2</span>"</span><br></pre></td></tr></table></figure></li></ul><h2 id="task-json"><a href="#task-json" class="headerlink" title="task.json"></a><code>task.json</code></h2><ul><li>下面注释部分按照实际情况改写<figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><span class="line">{</span><br><span class="line"> <span class="attr">"version"</span>: <span class="string">"2.0.0"</span>,</span><br><span class="line"> <span class="attr">"tasks"</span>: [</span><br><span class="line"> {</span><br><span class="line"> "label": "make", // ctrl + shift + b 调出vscode task的时候显示的名称</span><br><span class="line"> "command": "${workspaceFolder}/.vscode/make.bat", // make.bat的路径</span><br><span class="line"> "args": [</span><br><span class="line"> // 传递给make.bat的参数 %1和%2</span><br><span class="line"> "${relativeFile}", // 当前打开文件的路径</span><br><span class="line"> "./debug/${fileBasenameNoExtension}.out" // 编译后文件输出路径</span><br><span class="line"> ],</span><br><span class="line"> "problemMatcher": {</span><br><span class="line"> "owner": "cpp",</span><br><span class="line"> "fileLocation": ["relative", "${workspaceRoot}"],</span><br><span class="line"> "pattern": {</span><br><span class="line"> "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",</span><br><span class="line"> "file": 1,</span><br><span class="line"> "line": 2,</span><br><span class="line"> "column": 3,</span><br><span class="line"> "severity": 4,</span><br><span class="line"> "message": 5</span><br><span class="line"> }</span><br><span class="line"> },</span><br><span class="line"> "group": {</span><br><span class="line"> "kind": "build",</span><br><span class="line"> "isDefault": true</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> ],</span><br><span class="line"> "sourceFileMap": {}</span><br><span class="line">}</span><br></pre></td></tr></table></figure></li></ul><h2 id="launch-json"><a href="#launch-json" class="headerlink" title="launch.json"></a><code>launch.json</code></h2><ul><li>下面注释部分按照实际情况改写<figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br></pre></td><td class="code"><pre><span class="line">{</span><br><span class="line"> <span class="attr">"version"</span>: <span class="string">"0.2.0"</span>,</span><br><span class="line"> <span class="attr">"configurations"</span>: [</span><br><span class="line"> {</span><br><span class="line"> <span class="attr">"name"</span>: <span class="string">"(gdb)"</span>,</span><br><span class="line"> <span class="attr">"type"</span>: <span class="string">"cppdbg"</span>,</span><br><span class="line"> <span class="attr">"request"</span>: <span class="string">"launch"</span>,</span><br><span class="line"> <span class="attr">"program"</span>: <span class="string">"${fileBasenameNoExtension}.out"</span>,</span><br><span class="line"> <span class="attr">"args"</span>: [</span><br><span class="line"> // 调试时送给程序的参数相当于gdb中的 set args xxx</span><br><span class="line"> <span class="string">"test.log"</span>,</span><br><span class="line"> <span class="string">"100"</span></span><br><span class="line"> ],</span><br><span class="line"> "stopAtEntry": true, // 设为true时程序将暂停在程序入口处</span><br><span class="line"> "cwd": "/mnt/f/workspaces/c++/debug", // 调试程序时的工作目录</span><br><span class="line"> "environment": [],</span><br><span class="line"> "externalConsole": true,</span><br><span class="line"> "internalConsoleOptions": "openOnSessionStart",</span><br><span class="line"> "sourceFileMap": {</span><br><span class="line"> "/mnt/f/workspaces/c++/": "${workspaceFolder}" // 路径映射,修改路径为实际路径</span><br><span class="line"> },</span><br><span class="line"> "windows": {</span><br><span class="line"> "MIMode": "gdb",</span><br><span class="line"> "setupCommands": [</span><br><span class="line"> {</span><br><span class="line"> <span class="attr">"description"</span>: <span class="string">"Enable pretty-printing for gdb"</span>,</span><br><span class="line"> <span class="attr">"text"</span>: <span class="string">"-enable-pretty-printing"</span>,</span><br><span class="line"> <span class="attr">"ignoreFailures"</span>: <span class="literal">true</span></span><br><span class="line"> }</span><br><span class="line"> ]</span><br><span class="line"> },</span><br><span class="line"> "pipeTransport": {</span><br><span class="line"> "pipeCwd": "",</span><br><span class="line"> "pipeProgram": "c:\\Windows\\System32\\bash.exe",</span><br><span class="line"> "pipeArgs": ["-c"],</span><br><span class="line"> "debuggerPath": "/usr/bin/gdb"</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> ]</span><br><span class="line">}</span><br></pre></td></tr></table></figure></li></ul><h1 id="使用说明"><a href="#使用说明" class="headerlink" title="使用说明"></a>使用说明</h1><ul><li>一键 <code>F5</code> 编译运行<br>编译的时候实际就是通过 <code>cmd</code> 去执行 <code>bash</code> 命令,上面的例子中是先把 <code>debug</code> 下的 <code>.out</code> 删除,然后编译运行,可以直接在 <code>vscode</code> 的终端中看到运行结果</li></ul><h2 id="make-工程"><a href="#make-工程" class="headerlink" title="make 工程"></a><code>make</code> 工程</h2><ul><li>大点的工程都有 <code>makefile</code>,方法和上面的一样,只要改一下 <code>make.bat</code>就行了<figure class="highlight bat"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">bash -c "<span class="built_in">cd</span> src && make clean && make %<span class="number">1</span>"</span><br></pre></td></tr></table></figure></li></ul><h2 id="配置-go"><a href="#配置-go" class="headerlink" title="配置 go"></a>配置 <code>go</code></h2><ul><li><p><code>make.bat</code></p><figure class="highlight bat"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">bash -c "go run %<span class="number">1</span>"</span><br></pre></td></tr></table></figure></li><li><p><code>task.json</code></p><figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line">{</span><br><span class="line"> <span class="attr">"version"</span>: <span class="string">"2.0.0"</span>,</span><br><span class="line"> <span class="attr">"tasks"</span>: [</span><br><span class="line"> {</span><br><span class="line"> "label": "go", // 显示</span><br><span class="line"> "command": "${workspaceFolder}/.vscode/make.bat", // make.bat路径</span><br><span class="line"> "args": [</span><br><span class="line"> "/mnt/f/workspaces/go/${relativeFile}" // make.bat 的入参</span><br><span class="line"> ],</span><br><span class="line"> "problemMatcher": {</span><br><span class="line"> "owner": "go",</span><br><span class="line"> "fileLocation": ["relative", "${workspaceRoot}"],</span><br><span class="line"> "pattern": {</span><br><span class="line"> "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",</span><br><span class="line"> "file": 1,</span><br><span class="line"> "line": 2,</span><br><span class="line"> "column": 3,</span><br><span class="line"> "severity": 4,</span><br><span class="line"> "message": 5</span><br><span class="line"> }</span><br><span class="line"> },</span><br><span class="line"> "group": {</span><br><span class="line"> "kind": "build",</span><br><span class="line"> "isDefault": true</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> ],</span><br><span class="line"> "sourceFileMap": {}</span><br><span class="line">}</span><br></pre></td></tr></table></figure></li><li><p><code>launch.json</code></p><figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line">{</span><br><span class="line"> <span class="attr">"version"</span>: <span class="string">"0.2.0"</span>,</span><br><span class="line"> <span class="attr">"configurations"</span>: [</span><br><span class="line"> {</span><br><span class="line"> <span class="attr">"name"</span>: <span class="string">"golang"</span>,</span><br><span class="line"> <span class="attr">"type"</span>: <span class="string">"go"</span>,</span><br><span class="line"> <span class="attr">"request"</span>: <span class="string">"launch"</span>,</span><br><span class="line"> <span class="attr">"mode"</span>: <span class="string">"debug"</span>,</span><br><span class="line"> <span class="attr">"remotePath"</span>: <span class="string">""</span>,</span><br><span class="line"> <span class="attr">"port"</span>: <span class="number">2345</span>,</span><br><span class="line"> <span class="attr">"host"</span>: <span class="string">"127.0.0.1"</span>,</span><br><span class="line"> // "program": "${relativeFile}.go",</span><br><span class="line"> "program": "${workspaceRoot}/${relativeFile}",</span><br><span class="line"> "env": { "gopath": "F:\\workspaces\\golang" }, // $GOPATH路径</span><br><span class="line"> "args": [],</span><br><span class="line"> "showLog": true,</span><br><span class="line"> "trace": true</span><br><span class="line"> }</span><br><span class="line"> ]</span><br><span class="line">}</span><br></pre></td></tr></table></figure></li></ul>]]></content>
<summary type="html">
<!-- TOC -->
<ul>
<li><a href="#使用场景">使用场景</a></li>
<li><a href="#操作步骤">操作步骤</a><ul>
<li><a href="#开启-wsl并配置为-vscode-默认终端">开启 <code>wsl</cod
</summary>
<category term="开发环境" scheme="http://yoursite.com/categories/%E5%BC%80%E5%8F%91%E7%8E%AF%E5%A2%83/"/>
<category term="vscode" scheme="http://yoursite.com/tags/vscode/"/>
<category term="wsl" scheme="http://yoursite.com/tags/wsl/"/>
<category term="c++" scheme="http://yoursite.com/tags/c/"/>
</entry>
<entry>
<title>记一次Segment fault</title>
<link href="http://yoursite.com/2019/04/14/%E8%AE%B0%E4%B8%80%E6%AC%A1Segment%20fault/"/>
<id>http://yoursite.com/2019/04/14/记一次Segment fault/</id>
<published>2019-04-14T08:25:38.513Z</published>
<updated>2020-04-18T18:05:55.412Z</updated>
<content type="html"><![CDATA[<h1 id="重现"><a href="#重现" class="headerlink" title="重现"></a>重现</h1><ul><li><p>功能描述<br>把 <code>test.log</code> 文件每一行按照 <code>,</code> 进行切片,将一行中的所有分片存放到 <code>string</code> 数组中</p></li><li><p>样例<br><code>test.log</code> 中有很多行如下字符串</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">home,m_kepler,project</span><br></pre></td></tr></table></figure><p>目的是按照<code>,</code>切割,把子串存放到 string 数组中</p><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">string</span> strTmp[<span class="number">3</span>];</span><br><span class="line">strTmp[<span class="number">0</span>] = <span class="string">"home"</span></span><br><span class="line">strTmp[<span class="number">1</span>] = <span class="string">"m_kepler"</span></span><br><span class="line">strTmp[<span class="number">2</span>] = <span class="string">"project"</span></span><br></pre></td></tr></table></figure></li><li><p>出错的代码<br>这里不用 <code>strtok</code> 是因为 <code>,,</code> 也要算一个数据</p><figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line">fstream test;</span><br><span class="line"><span class="keyword">char</span> delim[] = <span class="string">","</span>;</span><br><span class="line"><span class="built_in">string</span> strLine;</span><br><span class="line"><span class="built_in">string</span> szstrTmp [<span class="number">3</span>];</span><br><span class="line"></span><br><span class="line">test.open(<span class="string">"./debug/test.log"</span>, ios::binary | ios::in);</span><br><span class="line"><span class="keyword">if</span>(!test)</span><br><span class="line"> perror(<span class="string">"open"</span>);</span><br><span class="line"></span><br><span class="line"><span class="keyword">while</span>(getline(test, strLine))</span><br><span class="line">{</span><br><span class="line"> <span class="keyword">int</span> i = <span class="number">0</span>; <span class="comment">// error1</span></span><br><span class="line"> <span class="keyword">char</span> *orgstr = strdup(strLine.c_str()); <span class="comment">// error2</span></span><br><span class="line"> <span class="keyword">for</span> (token = strsep(&orgstr, delim); token != <span class="literal">NULL</span>; token = strsep(&orgstr, delim))</span><br><span class="line"> {</span><br><span class="line"> szstrTmp[i] = token;</span><br><span class="line"> i++;</span><br><span class="line"> }</span><br><span class="line"> <span class="built_in">free</span>(orgstr);</span><br><span class="line">}</span><br><span class="line"><span class="keyword">return</span> <span class="number">0</span>;</span><br></pre></td></tr></table></figure></li></ul><h1 id="分析"><a href="#分析" class="headerlink" title="分析"></a>分析</h1><ul><li><p>像下面这样把两个循环条件才出来,运行报错 <code>Segmentation fault (core dumped)</code></p><figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">string</span> szstrTmp[<span class="number">3</span>];</span><br><span class="line"><span class="keyword">while</span>(getline(test,line))</span><br><span class="line">{</span><br><span class="line"> <span class="keyword">int</span> j =<span class="number">0</span>;</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i =<span class="number">0</span>; i < <span class="number">10</span>; i++)</span><br><span class="line"> {</span><br><span class="line"> szstrTmp[j] = <span class="string">"aaaa"</span>; <span class="comment">// gdb 调试报错此行</span></span><br><span class="line"> j++;</span><br><span class="line"> }</span><br><span class="line">}</span><br></pre></td></tr></table></figure></li><li><p>在 <code>while</code> 循环中使用 <code>strdup</code>,运行报错 <code>munmap_chunk(): invalid pointer</code></p><figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">string</span> szstrTmp[<span class="number">3</span>];</span><br><span class="line"><span class="keyword">while</span>(getline(test, line))</span><br><span class="line">{</span><br><span class="line"> <span class="keyword">int</span> i = <span class="number">0</span>;</span><br><span class="line"> <span class="keyword">char</span> *orgstr = strdup(line.c_str());</span><br><span class="line"> <span class="keyword">for</span> (token = strsep(&orgstr, delim), i = <span class="number">0</span>; token != <span class="literal">NULL</span>, i != <span class="number">3</span>; token = strsep(&orgstr, delim), i++)</span><br><span class="line"> {</span><br><span class="line"> szstrTmp[i] = token;</span><br><span class="line"> }</span><br><span class="line"> <span class="built_in">free</span>(orgstr); <span class="comment">// gbd 调试报错在此行</span></span><br><span class="line">}</span><br></pre></td></tr></table></figure></li></ul><h1 id="修复"><a href="#修复" class="headerlink" title="修复"></a>修复</h1><ul><li><p>不使用 <code>strdup</code> 、<code>for</code> 循环里多个条件限制</p></li><li><p>修复后的代码</p><figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line">fstream test;</span><br><span class="line"><span class="keyword">int</span> i = <span class="number">0</span>; <span class="comment">// ++++++</span></span><br><span class="line"><span class="keyword">char</span> delim[] = <span class="string">","</span>;</span><br><span class="line"><span class="built_in">string</span> strLine;</span><br><span class="line"><span class="built_in">string</span> szstrTmp [<span class="number">3</span>];</span><br><span class="line"></span><br><span class="line">test.open(<span class="string">"./debug/test.log"</span>, ios::binary | ios::in);</span><br><span class="line"><span class="keyword">if</span>(!test)</span><br><span class="line"> perror(<span class="string">"open"</span>);</span><br><span class="line"></span><br><span class="line"><span class="keyword">while</span>(getline(test, strLine))</span><br><span class="line">{</span><br><span class="line"> <span class="comment">// int i = 0; // error1 // ------</span></span><br><span class="line"> <span class="comment">// char *orgstr = strdup(strLine.c_str()); // error2 // ------</span></span><br><span class="line"></span><br><span class="line"> <span class="keyword">char</span> *orgstr = <span class="keyword">const_cast</span><<span class="keyword">char</span>*>(strLine.c_str());</span><br><span class="line"> <span class="comment">// for (token = strsep(&orgstr, delim), i = 0; token != NULL; token = strsep(&orgstr, delim)) // ------</span></span><br><span class="line"> <span class="keyword">for</span> (token = strsep(&orgstr, delim), i = <span class="number">0</span>; token != <span class="literal">NULL</span>, i < <span class="number">3</span>; token = strsep(&orgstr, delim), i++) <span class="comment">// ++++++</span></span><br><span class="line"> {</span><br><span class="line"> szstrTmp[i] = token;</span><br><span class="line"> <span class="comment">// i++; // ------</span></span><br><span class="line"> }</span><br><span class="line"> <span class="comment">// free(orgstr); // ------</span></span><br><span class="line">}</span><br><span class="line"><span class="keyword">return</span> <span class="number">0</span>;</span><br></pre></td></tr></table></figure></li></ul>]]></content>
<summary type="html">
<h1 id="重现"><a href="#重现" class="headerlink" title="重现"></a>重现</h1><ul>
<li><p>功能描述<br>把 <code>test.log</code> 文件每一行按照 <code>,</code> 进行切片,将
</summary>
<category term="Other" scheme="http://yoursite.com/categories/Other/"/>
<category term="Bug" scheme="http://yoursite.com/tags/Bug/"/>
</entry>
<entry>
<title>Hello World</title>
<link href="http://yoursite.com/2019/04/13/hello-world/"/>
<id>http://yoursite.com/2019/04/13/hello-world/</id>
<published>2019-04-13T05:53:38.839Z</published>
<updated>2020-04-18T18:27:27.070Z</updated>
<content type="html"><![CDATA[<div class="note info"> <p>quote test</p> </div><blockquote><p><a href="https://www.cnblogs.com/trista222/p/8017300.html" target="_blank" rel="noopener">结合hexo在GitHub上搭建个人博客——全过程</a></p></blockquote><p>Welcome to <a href="https://hexo.io/" target="_blank" rel="noopener">Hexo</a>! This is your very first post. Check <a href="https://hexo.io/docs/" target="_blank" rel="noopener">documentation</a> for more info. If you get any problems when using Hexo, you can find the answer in <a href="https://hexo.io/docs/troubleshooting.html" target="_blank" rel="noopener">troubleshooting</a> or you can ask me on <a href="https://github.com/hexojs/hexo/issues" target="_blank" rel="noopener">GitHub</a>.</p><h2 id="Quick-Start"><a href="#Quick-Start" class="headerlink" title="Quick Start"></a>Quick Start</h2><h3 id="Create-a-new-post"><a href="#Create-a-new-post" class="headerlink" title="Create a new post"></a>Create a new post</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="variable">$hexo</span> new <span class="string">"My New Post"</span></span><br></pre></td></tr></table></figure><p>More info: <a href="https://hexo.io/docs/writing.html" target="_blank" rel="noopener">Writing</a></p><h3 id="Run-server"><a href="#Run-server" class="headerlink" title="Run server"></a>Run server</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="variable">$hexo</span> server</span><br></pre></td></tr></table></figure><p>More info: <a href="https://hexo.io/docs/server.html" target="_blank" rel="noopener">Server</a></p><h3 id="Generate-static-files"><a href="#Generate-static-files" class="headerlink" title="Generate static files"></a>Generate static files</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="variable">$hexo</span> generate</span><br></pre></td></tr></table></figure><p>More info: <a href="https://hexo.io/docs/generating.html" target="_blank" rel="noopener">Generating</a></p><h3 id="Deploy-to-remote-sites"><a href="#Deploy-to-remote-sites" class="headerlink" title="Deploy to remote sites"></a>Deploy to remote sites</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="variable">$hexo</span> deploy</span><br></pre></td></tr></table></figure><p>More info: <a href="https://hexo.io/docs/deployment.html" target="_blank" rel="noopener">Deployment</a></p>]]></content>
<summary type="html">
<div class="note info">
<p>quote test</p>
</div>
<blockquote>
<p><a href="https://www.cnblogs.com/trista222/p/8017300.
</summary>
<category term="Other" scheme="http://yoursite.com/categories/Other/"/>
<category term="Other" scheme="http://yoursite.com/tags/Other/"/>
</entry>
</feed>