This commit is contained in:
chyyuu
2022-07-28 16:50:22 +00:00
parent 0fb63014e9
commit 66d853b80a
3 changed files with 6 additions and 7 deletions

View File

@@ -636,12 +636,11 @@ sudo chmod <span class="m">777</span> ./*
<p>打开对应实验目录下的 <code class="docutils literal notranslate"><span class="pre">Cargo.toml</span></code> 文件例如你在开发os8那么就是 <code class="docutils literal notranslate"><span class="pre">os8/Cargo.toml</span></code> 文件,在其结尾添加如下几行:</p>
<div class="highlight-json notranslate"><div class="highlight"><pre><span></span>[profile.release]
debug = true
opt-level = "s"
opt-level = 0
</pre></div>
</div>
<p>这段配置的意思是说我们要覆盖默认release模式编译的参数默认情况下release模式的编译会移除debug信息也就是 <code class="docutils literal notranslate"><span class="pre">debug=false</span></code> ,并且使用 <code class="docutils literal notranslate"><span class="pre">opt-level=2</span></code> ,也就是最高级别的优化进行编译,这样会导致打断点的时候很痛苦,很多代码都被优化的面目全非,对调试很不友好。</p>
<p>在上述代码中我们将debug信息保留并且使用 <code class="docutils literal notranslate"><span class="pre">s</span></code> 级别进行优化,这里可选的其他级别还有 0、1、2、z、s三种其中设置成2的话相当于没有设置因为release模式默认就是2如果设置成0的话经过我的实验会导致内核加载的时候直接崩溃掉我初步猜测是因为0表示关闭优化关闭后的内核二进制文件体积有点大以上是乱猜的时间有限没有去详细验证感兴趣的同学欢迎后续指正
如果设置为1的话感觉还是会有很多地方被优化导致代码很多地方无法打断点。经过个人实验感觉选择 <code class="docutils literal notranslate"><span class="pre">s</span></code> 级别可以在代码大小和优化之间取得一个比较好的平衡。</p>
<p>在上述代码中我们将debug信息保留并且使用 <code class="docutils literal notranslate"><span class="pre">0</span></code> 级别进行优化,这里可选的其他级别还有 0、1、2、z、s 等。如果设置为 <code class="docutils literal notranslate"><span class="pre">1</span></code><code class="docutils literal notranslate"><span class="pre">2</span></code> 感觉还是会有很多地方被优化导致代码很多地方无法打断点。如果设置成0意味着编译器没有编译优化这样可以最大化地保证打断点的地方就是实际执行的地方。所以在这里优先选择设置为 <code class="docutils literal notranslate"><span class="pre">0</span></code> 级别。经过个人实验,感觉选择 <code class="docutils literal notranslate"><span class="pre">s</span></code> 级别可以在代码大小和优化之间取得一个比较好的平衡。</p>
<p>第四步修改Makefile文件</p>
<p>打开对应实验目录下的 <code class="docutils literal notranslate"><span class="pre">Makefile</span></code> 文件例如你在开发os8那么就是 <code class="docutils literal notranslate"><span class="pre">os8/Makefile</span></code> 文件,在其结尾添加如下几行:</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>dbg: build

View File

@@ -426,12 +426,12 @@ VSCode 可视化调试支持
[profile.release]
debug = true
opt-level = "s"
opt-level = 0
这段配置的意思是说我们要覆盖默认release模式编译的参数默认情况下release模式的编译会移除debug信息也就是 ``debug=false`` ,并且使用 ``opt-level=2`` ,也就是最高级别的优化进行编译,这样会导致打断点的时候很痛苦,很多代码都被优化的面目全非,对调试很不友好。
在上述代码中我们将debug信息保留并且使用 ``s`` 级别进行优化,这里可选的其他级别还有 0、1、2、z、s三种其中设置成2的话相当于没有设置因为release模式默认就是2如果设置成0的话经过我的实验会导致内核加载的时候直接崩溃掉我初步猜测是因为0表示关闭优化关闭后的内核二进制文件体积有点大以上是乱猜的时间有限没有去详细验证感兴趣的同学欢迎后续指正
如果设置为1的话感觉还是会有很多地方被优化导致代码很多地方无法打断点。经过个人实验感觉选择 ``s`` 级别可以在代码大小和优化之间取得一个比较好的平衡。
在上述代码中我们将debug信息保留并且使用 ``0`` 级别进行优化,这里可选的其他级别还有 0、1、2、z、s 等。如果设置为 ``1`` 或 ``2`` 感觉还是会有很多地方被优化导致代码很多地方无法打断点。如果设置成0意味着编译器没有编译优化这样可以最大化地保证打断点的地方就是实际执行的地方。所以在这里优先选择设置为 ``0`` 级别。经过个人实验,感觉选择 ``s`` 级别可以在代码大小和优化之间取得一个比较好的平衡。
第四步修改Makefile文件

File diff suppressed because one or more lines are too long