<div class="xblock xblock-public_view xblock-public_view-vertical" data-course-id="course-v1:MOOC-FLOSS+101+2021_1" data-init="VerticalStudentView" data-runtime-class="LmsRuntime" data-runtime-version="1" data-block-type="vertical" data-usage-id="block-v1:MOOC-FLOSS+101+2021_1+type@vertical+block@chap-07-seq-03-ver-01" data-request-token="ac0031e2903711ee8c631237928d7ffd" data-graded="False" data-has-score="False">
<div class="vert-mod">
<div class="vert vert-0" data-id="block-v1:MOOC-FLOSS+101+2021_1+type@html+block@chap-07-seq-03-ver-01-html-01">
<div class="xblock xblock-public_view xblock-public_view-html xmodule_display xmodule_HtmlBlock" data-course-id="course-v1:MOOC-FLOSS+101+2021_1" data-init="XBlockToXModuleShim" data-runtime-class="LmsRuntime" data-runtime-version="1" data-block-type="html" data-usage-id="block-v1:MOOC-FLOSS+101+2021_1+type@html+block@chap-07-seq-03-ver-01-html-01" data-request-token="ac0031e2903711ee8c631237928d7ffd" data-graded="False" data-has-score="False">
<script type="json/xblock-args" class="xblock-json-init-args">
{"xmodule-type": "HTMLModule"}
</script>
<div class="edit-link-wrapper"><div class="edit-link"><p style="text-align: right;"><a href="https://gitlab.com/-/ide/project/mooc-floss/mooc-floss/edit/master/-/course/html/chap-07-seq-03-ver-01-html-01.html" target="_blank"><i class="fa fa-pencil mr-1"></i> Edit on Gitlab</a></p></div><div class="edit-link-original-content"><p>A frequent mistake when failing to replicate a bug is to be on the wrong version of the code, and few checks need to be done to ensure you're on the right track</p>
<h4>The right branch ?</h4>
<p>For bugs that have not existed of all eternity, there is a time when the bug was <em>introduced</em>. Which means that there are points in the code where a bug is present, and points in time where it's not. Since many projects use git, which has a branching model, there could be whole branches with the bugs, or without. If a bug was introduced in a specific release, it's always possible that it only exists in the branch containing that release, and that attempts to replicate it in the main (default) branch are doomed to fail. When in doubt about a bug's presence, make sure you use the exact same version as the bug reporter first, to see if you can reproduce it there… It can also happen that developers fix something, and their change happen to fix the bug you're looking at, and if they don't realize, the bug could actually be closed.</p>
<h4>The right dependencies ?</h4>
<p>Sometimes, bugs are not caused by the code you're looking at, but by <em>dependencies. </em>When practical, it's always a good practice to see if newer or older versions of dependencies involved in a bug could lead to a change in behavior.</p>
<h4>Anything cached ?</h4>
<p>Usually, issues with cached builds tend to manifest themselves by a programmer wondering why whatever they're trying does not have any effect - The code they run to <em>try</em> things (their changes, or replication steps, or something else) is not the code they're thinking of, but a cached version of another code, which could be the system version, or an old build, or something similar. If you're not sure anything you do has an effect, a recommendation would be <em>make it crash. </em>If you can't, then maybe your modifications are not what you run.</p></div></div>
</div>
</div>
</div>
<script type="text/javascript">
(function (require) {
require(['/static/js/dateutil_factory.a28baef97506.js?raw'], function () {
require(['js/dateutil_factory'], function (DateUtilFactory) {
DateUtilFactory.transform('.localized-datetime');
});
});
}).call(this, require || RequireJS.require);
</script>
<script>
function emit_event(message) {
parent.postMessage(message, '*');
}
</script>
</div>
<div class="xblock xblock-public_view xblock-public_view-vertical" data-course-id="course-v1:MOOC-FLOSS+101+2021_1" data-init="VerticalStudentView" data-runtime-class="LmsRuntime" data-runtime-version="1" data-block-type="vertical" data-usage-id="block-v1:MOOC-FLOSS+101+2021_1+type@vertical+block@chap-07-seq-03-ver-02" data-request-token="ac0031e2903711ee8c631237928d7ffd" data-graded="False" data-has-score="False">
<div class="vert-mod">
<div class="vert vert-0" data-id="block-v1:MOOC-FLOSS+101+2021_1+type@html+block@chap-07-seq-03-ver-02-html-01">
<div class="xblock xblock-public_view xblock-public_view-html xmodule_display xmodule_HtmlBlock" data-course-id="course-v1:MOOC-FLOSS+101+2021_1" data-init="XBlockToXModuleShim" data-runtime-class="LmsRuntime" data-runtime-version="1" data-block-type="html" data-usage-id="block-v1:MOOC-FLOSS+101+2021_1+type@html+block@chap-07-seq-03-ver-02-html-01" data-request-token="ac0031e2903711ee8c631237928d7ffd" data-graded="False" data-has-score="False">
<script type="json/xblock-args" class="xblock-json-init-args">
{"xmodule-type": "HTMLModule"}
</script>
<div class="edit-link-wrapper"><div class="edit-link"><p style="text-align: right;"><a href="https://gitlab.com/-/ide/project/mooc-floss/mooc-floss/edit/master/-/course/html/chap-07-seq-03-ver-02-html-01.html" target="_blank"><i class="fa fa-pencil mr-1"></i> Edit on Gitlab</a></p></div><div class="edit-link-original-content"><p>If you're lost in code, there are always places to get help:</p>
<h4>Code comments</h4>
<p>Comments are almost always your friends. If something is amiss in the code, then there are chances that it is commented, or at least that it should be documented (and that a merge request adding comments there to explain it would be well received). Standard places to look for comments could be at the place, or above the function or class definition, or at the top of the file (or in the corresponding header/interface file).</p>
<h4>Developer documentation</h4>
<p>Sometimes, projects have dedicated websites or wiki holding developer documentation, which may be linked from the project's website.</p>
<h4>Code owners</h4>
<p>In some projects, there is the notion of <em>code owners, </em>which is a mean to denote people who have a responsibility, and usually some level of understanding, on a part of the codebase. If so, you've found the right people to ask questions.</p>
<h4>Ask for help</h4>
<p>Otherwise, you can always ask the community. Make sure you've done your homework first and gave an honest try at trying to understand what's going on, or checked places likely to have the information you're asking, then don't feel shy, if it's worth asking, then you can make sure others don't have to ask, and put the answers you're getting as comments, or in the developer documentation :)</p></div></div>
</div>
</div>
</div>
<script type="text/javascript">
(function (require) {
require(['/static/js/dateutil_factory.a28baef97506.js?raw'], function () {
require(['js/dateutil_factory'], function (DateUtilFactory) {
DateUtilFactory.transform('.localized-datetime');
});
});
}).call(this, require || RequireJS.require);
</script>
<script>
function emit_event(message) {
parent.postMessage(message, '*');
}
</script>
</div>
<div class="xblock xblock-public_view xblock-public_view-vertical" data-course-id="course-v1:MOOC-FLOSS+101+2021_1" data-init="VerticalStudentView" data-runtime-class="LmsRuntime" data-runtime-version="1" data-block-type="vertical" data-usage-id="block-v1:MOOC-FLOSS+101+2021_1+type@vertical+block@chap-07-seq-03-ver-03" data-request-token="ac0031e2903711ee8c631237928d7ffd" data-graded="False" data-has-score="False">
<div class="vert-mod">
<div class="vert vert-0" data-id="block-v1:MOOC-FLOSS+101+2021_1+type@html+block@chap-07-seq-03-ver-03-html-01">
<div class="xblock xblock-public_view xblock-public_view-html xmodule_display xmodule_HtmlBlock" data-course-id="course-v1:MOOC-FLOSS+101+2021_1" data-init="XBlockToXModuleShim" data-runtime-class="LmsRuntime" data-runtime-version="1" data-block-type="html" data-usage-id="block-v1:MOOC-FLOSS+101+2021_1+type@html+block@chap-07-seq-03-ver-03-html-01" data-request-token="ac0031e2903711ee8c631237928d7ffd" data-graded="False" data-has-score="False">
<script type="json/xblock-args" class="xblock-json-init-args">
{"xmodule-type": "HTMLModule"}
</script>
<div class="edit-link-wrapper"><div class="edit-link"><p style="text-align: right;"><a href="https://gitlab.com/-/ide/project/mooc-floss/mooc-floss/edit/master/-/course/html/chap-07-seq-03-ver-03-html-01.html" target="_blank"><i class="fa fa-pencil mr-1"></i> Edit on Gitlab</a></p></div><div class="edit-link-original-content"><p>Working in git has many advantages to find things in the code, look at the history, and find out when, or why, changes have happened. When debugging, it is useful to be able to harness the full power of git searching tools. Here is a selection of the ones we find most useful for investigating a codebase:</p>
<h4>git grep</h4>
<p><code>git grep</code> something will help you find your way around the codebase. If you find a variable, class name, or any word, and ponder « Who uses that? Where is it defined? », then git grep can answer you by looking at the whole repo and doing the equivalent of <code>grep -rI</code> on versioned files, even in some cases where your IDE of choice would not help you.</p>
<h4>git log <file></h4>
<p>If you are wondering how often a file gets changes, what were the latest changes in it, and even <strong>why</strong> it got changed, then <code>git log</code> is your friend. It will tell you the commits that modified the given file, as well as the commit message, usually explaining the rationale of the change of that commit.</p>
<h4>git blame</h4>
<p>You think you found a line at the root of your issue, and now you're curious. Who put that here? Why? <code>git blame</code> is now your tool of choice. It will tell you who wrote any line, and when, with the latest commit modifying it. With it, one can look at the commit, find out if the logic it implement is sound, or was at the time it was written, and what it was supposed to do.</p>
<h4>git bisect</h4>
<p>If you have a bug, and you do know for sure that is has not existed of all eternity, plus you have a fast way of testing it, then this tool is the exact weapon you're looking for. Given a time where things worked, and a time where things did not, <code>git bisect</code> will perform a <em>binary search</em> for you in the commit tree, ending up in the exact commit that introduced your target behavior. Now you know where to look! </p>
<h4>git status</h4>
<p>That one is not typically used for investigation, but there are many cases where interacting with git can be a pain, and you can be lost, not knowing what your current state of the code actually is. <code>git status</code> will always be your compass and your guide, as long as you can carefully read its output.</p></div></div>
</div>
</div>
</div>
<script type="text/javascript">
(function (require) {
require(['/static/js/dateutil_factory.a28baef97506.js?raw'], function () {
require(['js/dateutil_factory'], function (DateUtilFactory) {
DateUtilFactory.transform('.localized-datetime');
});
});
}).call(this, require || RequireJS.require);
</script>
<script>
function emit_event(message) {
parent.postMessage(message, '*');
}
</script>
</div>
<div class="xblock xblock-public_view xblock-public_view-vertical" data-course-id="course-v1:MOOC-FLOSS+101+2021_1" data-init="VerticalStudentView" data-runtime-class="LmsRuntime" data-runtime-version="1" data-block-type="vertical" data-usage-id="block-v1:MOOC-FLOSS+101+2021_1+type@vertical+block@chap-07-seq-03-ver-04" data-request-token="ac0031e2903711ee8c631237928d7ffd" data-graded="False" data-has-score="False">
<div class="vert-mod">
<div class="vert vert-0" data-id="block-v1:MOOC-FLOSS+101+2021_1+type@html+block@chap-07-seq-03-ver-04-html-01">
<div class="xblock xblock-public_view xblock-public_view-html xmodule_display xmodule_HtmlBlock" data-course-id="course-v1:MOOC-FLOSS+101+2021_1" data-init="XBlockToXModuleShim" data-runtime-class="LmsRuntime" data-runtime-version="1" data-block-type="html" data-usage-id="block-v1:MOOC-FLOSS+101+2021_1+type@html+block@chap-07-seq-03-ver-04-html-01" data-request-token="ac0031e2903711ee8c631237928d7ffd" data-graded="False" data-has-score="False">
<script type="json/xblock-args" class="xblock-json-init-args">
{"xmodule-type": "HTMLModule"}
</script>
<div class="edit-link-wrapper"><div class="edit-link"><p style="text-align: right;"><a href="https://gitlab.com/-/ide/project/mooc-floss/mooc-floss/edit/master/-/course/html/chap-07-seq-03-ver-04-html-01.html" target="_blank"><i class="fa fa-pencil mr-1"></i> Edit on Gitlab</a></p></div><div class="edit-link-original-content"><p>If you have no idea how to fix an issue that you can reproduce, here are some tips and tricks you can try. We cannot guarantee they will always apply in your case, but offer a good starting point if you are stuck.</p>
<h3>Printf debugging and asserts</h3>
<p>If you're unsure what the code you're modifying is actually doing, or how variables evolve over time, you can put print statements in the code to show what variables are, and use asserts to immediately stop the code when something that you think "should not happen" is in fact happening.</p>
<h3>Use debuggers</h3>
<p>Compiled languages (like C) usually come with debuggers (e.g. <em>gdb</em> or <em>lldb</em>) that you can use to place breakpoints, and do step by step executions of functions, either directly or through your IDE of choice.</p>
<h3>Memory issues</h3>
<p>When using an unsafe language like C or C++ where it's possible to introduce memory issues, there are specific tools that can help you, most notably memory inspectors like <em>valgrind</em>, or compiling with things like <em>address sanitizer</em> (ASAN). These tools are specifically made to detect thos issues.</p>
<h3>Minimal Example, bisection</h3>
<p>To isolate the smallest portion of code that triggers a bug, you will usually need to simplify the code (or the input) until the bug disappears. Alternatively, start over from a known good state and compare execution. In both cases, the good approach will need some kind of <em>bisection </em>: working with smaller and smaller changesets working or non-working until you get the exact point creating the issue.</p>
<h3><a href="https://en.wikipedia.org/wiki/Rubber_duck_debugging">Rubber duck debugging</a></h3>
<p>always useful</p></div></div>
</div>
</div>
</div>
<script type="text/javascript">
(function (require) {
require(['/static/js/dateutil_factory.a28baef97506.js?raw'], function () {
require(['js/dateutil_factory'], function (DateUtilFactory) {
DateUtilFactory.transform('.localized-datetime');
});
});
}).call(this, require || RequireJS.require);
</script>
<script>
function emit_event(message) {
parent.postMessage(message, '*');
}
</script>
</div>