diff options
Diffstat (limited to 'files/pt-br/tools/debugger')
-rw-r--r-- | files/pt-br/tools/debugger/how_to/set_watch_expressions/index.html (renamed from files/pt-br/tools/debugger/how_to/examine,_modify,_and_watch_variables/index.html) | 0 | ||||
-rw-r--r-- | files/pt-br/tools/debugger/index.html | 448 | ||||
-rw-r--r-- | files/pt-br/tools/debugger/set_a_logpoint/index.html | 53 |
3 files changed, 501 insertions, 0 deletions
diff --git a/files/pt-br/tools/debugger/how_to/examine,_modify,_and_watch_variables/index.html b/files/pt-br/tools/debugger/how_to/set_watch_expressions/index.html index 232074130f..232074130f 100644 --- a/files/pt-br/tools/debugger/how_to/examine,_modify,_and_watch_variables/index.html +++ b/files/pt-br/tools/debugger/how_to/set_watch_expressions/index.html diff --git a/files/pt-br/tools/debugger/index.html b/files/pt-br/tools/debugger/index.html new file mode 100644 index 0000000000..225f4cb20a --- /dev/null +++ b/files/pt-br/tools/debugger/index.html @@ -0,0 +1,448 @@ +--- +title: Depurador +slug: Tools/Depurador +translation_of: Tools/Debugger +--- +<div>{{ToolsSidebar}}</div> + +<p>O Depurador Javascript permite percorrer o código JavaScript e examinar ou modificar seu estado para ajudar a localizar bugs.</p> + +<p>Você pode usá-lo para depurar código executando localmente no Firefox ou executando remotamente, por exemplo em um dispositivo Firefox OS ou Firefox para android. Este guia assume que você está depurando localmente, mas é na maioria das vezes aplicável para depuração remota também. Veja <a href="/en-US/docs/Tools/Remote_Debugging">o guia para depuração remota</a> (inglês) para as diferenças.</p> + +<p>{{EmbedYouTube("sK8KU8oiF8s")}}</p> + +<p>Para Abrir o Depurador selecione "Depurador" no submenu do Menu do Firefox (ou menu de Ferramentas , se você exibir a barra de menu ou estiver no Mac OS X), ou pressionando Control+Shift +S (Command -Option- S se estiver no Mac OS X) .</p> + +<p>A <a href="https://developer.mozilla.org/en-US/docs/Tools/DevTools_Window" title="/en-US/docs/Tools/DevTools_Window">Toolbox</a> aparece na parte inferior da janela do navegador, com o depurador ativado. Aqui está o que aparece quando você abrí-lo primeiro:</p> + +<p><img alt="" src="https://mdn.mozillademos.org/files/7019/01-overview-startup.png" style="display: block; margin-left: auto; margin-right: auto;">E aqui está o que aparece no meio de uma sessão de depuração:</p> + +<p><img alt="" src="https://mdn.mozillademos.org/files/7021/02-overview-session.png" style="display: block; margin-left: auto; margin-right: auto;">Neste guia, vamos primeiro ter um rápido passeio de interface do usuário do depurador, em seguida, iremos descrever como executar algumas tarefas comuns de depuração.</p> + +<h2 id="A_Interface_do_Usuário_para_Depurador">A Interface do Usuário para Depurador</h2> + +<p>A UI (Interface de Usuário) do depurador é dividida em seis seções principais, que abrangerá uma de cada vez:</p> + +<ul> + <li><a href="#toolbar">barra de ferramentas</a></li> + <li><a href="#source-list-pane">lista de código fonte </a></li> + <li><a href="/en-US/docs/Tools/Debugger#Call_stack_pane">painel de lista de chamados</a> (novo no Firefox 29)</li> + <li><a href="#source-pane">painel de fontes</a></li> + <li><a href="#variables-pane">painel de variáveis</a></li> + <li><a href="#events-pane">painel de eventos</a></li> +</ul> + +<p><img alt="" src="https://mdn.mozillademos.org/files/7063/03-ui-sections.png" style="display: block; margin-left: auto; margin-right: auto;"></p> + +<h3 id="Painel_de_códigos_fontes"><a name="source-list-pane">Painel de códigos fontes</a></h3> + +<p>O painel de lista de origem, lista todos os arquivos de origem JS carregados na página, e permite que você selecione um para depuração. A partir do Firefox 29, a origem do painel de lista, compartilha sua tela de imóveis com a pilha de chamadas do painel, e você pode usar as guias na parte superior do painel para alternar entre elas.</p> + +<p><img alt="" src="https://mdn.mozillademos.org/files/7025/04-source-list.png" style="display: block; margin-left: auto; margin-right: auto;">Arquivos de origem são agrupados sob diferentes rubricas de acordo com onde eles são carregados. Você pode selecionar qualquer um desses arquivos e eles serão carregados para o <a href="#source-pane" title="#source-pane">painel de código</a>.<img alt="" src="https://mdn.mozillademos.org/files/7071/24-source-list-details.png" style="display: block; margin-left: auto; margin-right: auto;"><br> + Quaisquer pontos de interrupção que você definiu em um arquivo de origem estão listados no painel da lista de origem sob o nome de arquivo. A caixa de seleção ao lado de cada ponto de interrupção permite você ativá-lo / desativá-lo. Clicando com o botão direito na entrada do ponto de interrupção na lista, mostra um menu de contexto permitindo:</p> + +<ul> + <li>ativar, desativar ou remover este ponto de interrupção, todos os pontos de interrupção, ou todos os pontos de interrupção exceto este</li> + <li>fazer este ponto de interrupção condicional (ou editar as suas condições, se já for condicional)</li> +</ul> + +<p>Os três ícones no inferior do painel de código fonte permitem habilitar a caixa-preta, impressão agradável de arquivos JS minificados e alternar todos os pontos de interrupção entre ativos e inativos.</p> + + + +<h4 id="Caixa-Preta_Black_Boxing">Caixa-Preta (Black Boxing)</h4> + +<p>O olho no canto inferior esquerdo do painel é um botão que habilita a <a href="#black-box-a-source">caixa-preta</a> à fonte atualmente selecionada. Black boxing é útil para fontes as quais está usando, mas não debugando, como bibliotecas como jQuery. Se uma fonte esté em black box, é assumido que não há interesse em debugar: qualquer breakpoint dentro da fonte será desabilitado, e o debugger pulará quando estiver fazendo o passo-a-passo do código.</p> + +<p>Nas versões do Firefox antes do 27, o ícone do olho aparece próximo ao nome do arquivo fonte quando passar o mouse sobre ele.</p> + +<h4 id="Impressão_agradável_Pretty_Print">Impressão agradável (Pretty Print)</h4> + +<p>O par de chaves <code>{}</code> habilita a função <a href="http://en.wikipedia.org/wiki/Prettyprint">pretty-print</a> tornando o código desminificado, permitindo uma melhor leitura.</p> + +<h4 id="Alternar_entre_todos_os_pontos_de_interrupção_Toggle_all_breakpoints">Alternar entre todos os pontos de interrupção (Toggle all breakpoints)</h4> + +<div class="geckoVersionNote"> +<p>O botão Toggle all breakpoints é novo no Firefox 29.</p> +</div> + +<p>O botão vai desabilitar todos os breakpoints, ou reabilitá-los, numa única ação. Isso torna fácil mudar entre rodar um programa e fazer o passo-a-passo por ele.</p> + +<h3 id="Painel_pilha_de_chamada">Painel pilha de chamada</h3> + +<div class="geckoVersionNote"> +<p>The call stack pane is new in Firefox 29.</p> +</div> + +<p>Na outra aba do lado esquerdo do painel de depuração é exibida na vertical a pilha de chamadas:</p> + +<p><img alt="" src="https://mdn.mozillademos.org/files/7081/23-call-stack.png" style="display: block; margin-left: auto; margin-right: auto;">Cada linha representa um nível na pilha de chamada com a chamada atual no topo do painel. As linhas mostram o nome das funções que estão sendo executadas atualmente e um link para o arquivo fonte e o número da linha.</p> + +<h3 id="Painel_de_arquivos"><a name="source-pane">Painel de arquivos</a></h3> + +<p>Esse painel exibe os arquivos JS que foram carregados atualmente. Os pontos de interrupção(breakpoints) são sinalizados através de um círculo azul próximo ao numero da linha. Enquanto os pontos de interrupção que você atingiu têm uma flecha verde dentro do círculo:</p> + +<p><img alt="" src="https://mdn.mozillademos.org/files/7031/07-breakpoint-hit.png" style="display: block; margin-left: auto; margin-right: auto;">No painel de arquivo, no menu de contexto habilita você:</p> + +<ul> + <li>Definir um ponto de interrupção</li> + <li>Definir um ponto de interrupção condicional</li> + <li> Adicionar a visão de uma expressão selecionada</li> + <li>Pesquisa ou filtra usando o <a href="#script filter" title="#script filter">script filter</a></li> +</ul> + +<h4 id="Popup_em_variáveis">Popup em variáveis</h4> + +<div class="geckoVersionNote"> +<p>O surgimento de Popup de uma variável é novo no Firefox 28.</p> +</div> + +<p>Se você passar o mouse em cima de uma variável, no painel de variáveis, aparece um popup mostrando a você o valor da variável atual:</p> + +<p><img alt="" src="https://mdn.mozillademos.org/files/7033/08-variable-popup.png" style="display: block; margin-left: auto; margin-right: auto;">Isso permite que você veja rapidamente uma variável sem sem ter que abrir e pesquisar o <a href="/en-US/docs/Tools/Debugger#Variables_pane">Painel de Variáveis</a></p> + +<h3 id="Barra_de_Ferramentas"><a name="toolbar">Barra de Ferramentas</a></h3> + +<p>A barra de ferramentas é composta por quatro seções:</p> + +<ul> + <li>uma linha de botões para controlhar o movimento através de um script</li> + <li>uma visualização da pilha de chamadas</li> + <li>o filtro do script</li> + <li>botões para mostrar/esconder os paines de <a href="#variables-pane" title="#variables-pane">variaveis</a> e <a href="#events-pane">eventos</a>, e controlar as configurações de debugador</li> +</ul> + +<p><img alt="" src="https://mdn.mozillademos.org/files/7035/09-toolbar.png" style="display: block; margin-left: auto; margin-right: auto;">Os quatro botões à esquerda executam as seguintes funções:</p> + +<ul> + <li><strong>Pause/Resume</strong> (F6): pauses or resumes execution of the script you're debugging. When it's blue and "pressed", as above, that means the script is paused, either because you've paused it with this button or because you've hit a breakpoint.</li> + <li><strong>Step Over</strong> (F7): steps across the current line of JavaScript code.</li> + <li><strong>Step Into</strong> (F8): steps into the function call on the current line of JavaScript code.</li> + <li><strong>Step Out</strong> (Shift-F8): runs the script until the current function exits.</li> +</ul> + +<p>The call stack visualisation shows the call stack at the point execution is paused.</p> + +<h4 id="Script_filter"><a name="script filter">Script filter</a></h4> + +<p>The script filter enables you to search in all three of the debugger's panes. By prefixing the filter expression with one of several special characters, the filter provides various different functions.</p> + +<dl> +</dl> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">Prefix</th> + <th scope="col">Function</th> + </tr> + </thead> + <tbody> + <tr> + <td>None</td> + <td>Filter the scripts shown in the <a href="#source-list-pane" title="#source-list-pane">source list pane</a>.</td> + </tr> + <tr> + <td>!</td> + <td>Search for the string across all files.</td> + </tr> + <tr> + <td>@</td> + <td>Search for function definitions, across all files, containing the string.</td> + </tr> + <tr> + <td>#</td> + <td>Search for the string in the file currently open in the <a href="#source-pane" title="#source-pane">source pane</a>.</td> + </tr> + <tr> + <td>:</td> + <td>Go to the line given in the file currently open in the <a href="#source-pane" title="#source-pane">source pane</a>.</td> + </tr> + <tr> + <td>*</td> + <td>Filter the variables shown in the <a href="#variables-pane" title="#variables-pane">variables pane</a>.</td> + </tr> + </tbody> +</table> + +<p>These options are shown in a pop-up when you click in the filter, and they're also accessible from the context menu in the <a href="#source-pane" title="#source-pane">source pane</a>. Prefixes can be combined to form more powerful queries, like "file.js:12", which will open file.js and highlight line 12, or "mod#onLoad", which will find the string onLoad in all files containing mod in their name. Hitting the Enter key after searching will cycle between the matches found.</p> + +<h4 id="Debugger_settings"><a name="debugger-settings">Debugger settings</a></h4> + +<p>At the right-hand end of the toolbar are two more buttons. The first of these shows and hides the <a href="#variables-pane" title="#variables-pane">variables</a> and <a href="#events-pane">events</a> panes, and the second enables you to toggle various debugger settings:</p> + +<table class="standard-table"> + <tbody> + <tr> + <td style="width: 20%;"><strong>Auto Prettify Minified Sources</strong></td> + <td> + <p>With this option enabled, the debugger will automatically detect minified JS files and <a href="/en-US/docs/Tools/Debugger#Pretty-print_a_minified_file">pretty-print</a> them.</p> + + <div class="geckoVersionNote"> + <p>This option is new in Firefox 29.</p> + </div> + </td> + </tr> + <tr> + <td style="width: 20%;"><strong>Pause on Exceptions</strong></td> + <td>When this option is enabled, execution of the script will automatically pause whenever a JavaScript exception is thrown.</td> + </tr> + <tr> + <td style="width: 20%;"><strong>Ignore Caught Exceptions</strong></td> + <td>If this option is set (it is set by default) and "Pause on exceptions" is set, then execution will pause on an exception only if that exception is not caught. This is usually the behavior you want (you don't generally want to pause execution when an exception that is thrown is caught, since that generally indicates that your program is handling it properly).</td> + </tr> + <tr> + <td><strong>Show Panes on Startup</strong></td> + <td>When this option is enabled, the debugger's <a href="#variables-pane" title="#variables-pane">variables pane</a> is visible when you first start the debugger.</td> + </tr> + <tr> + <td><strong>Show Only Enumerable Properties</strong></td> + <td>Enabling this option adds a "Filter variables" search box to the <a href="#variables-pane" title="#variables-pane">variables panel</a>, so that you can filter the displayed list of variables.</td> + </tr> + <tr> + <td><strong>Show Variables Filter Box</strong></td> + <td>Do not display non-enumerable JavaScript properties</td> + </tr> + <tr> + <td><strong>Show Original Sources</strong></td> + <td>Enabling this option will make the debugger use <a href="http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/" title="http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/">source maps</a>, if they are available, to display the original source for code which has been combined, minified, or even compiled to JavaScript from a language like CoffeeScript.</td> + </tr> + </tbody> +</table> + +<dl> +</dl> + +<h3 id="Variables_pane"><a name="variables-pane">Variables pane</a></h3> + +<p>The variables pane is where you can examine, and modify, the internal state of the script as it's executing:</p> + +<p><img alt="" src="https://mdn.mozillademos.org/files/7037/10-variables-pane.png" style="display: block; margin-left: auto; margin-right: auto;">The variables pane shares its screen real estate with the <a href="#events-pane">events pane</a>, and you can use the tabs at the top of the pane to switch between them.</p> + +<h4 id="Examining_variables">Examining variables</h4> + +<p>Variables are grouped by scope: in Function scope you'll see the built-in <code>arguments</code> and <code>this</code> variables as well as local variables defined by the function like <code>user</code> and <code>greeting</code>. Similarly, in Global scope you'll see global variables you've defined, like <code>greetme</code>, as well as built-in globals like <code>localStorage</code> and <code>console</code>.</p> + +<p>Each object can be expanded using a disclosure triangle to show its members.</p> + +<p>Pointing your cursor at a variable's name displays a tooltip that provides additional information about the variable; for example, pointing at the <code>greeting</code> object displays "<s>configurable</s> enumerable writable". See <a href="/en-US/docs/JavaScript/Reference/Global_Objects/Object/defineProperty" title="/en-US/docs/JavaScript/Reference/Global_Objects/Object/defineProperty"><code>Object.defineProperty()</code></a> for details on what these property descriptors mean.</p> + +<p>You can filter the variables that are displayed, either by using the "*" modifier in the <a href="#script-filter" title="#script-filter">script filter</a>, or by typing into the filter variables box, if you have enabled this in the <a href="#debugger-settings" title="#debugger-settings">debugger settings</a>.</p> + +<h4 id="Modifying_variables">Modifying variables</h4> + +<p>You can change a variable's value by clicking on its current value and entering a new one; for example, if you click on <code>"Hi, Dr. Nick!"</code> next to <code>greeting</code>, you can edit the value.</p> + +<h4 id="Watch_expressions"><a name="watch-expressions">Watch expressions</a></h4> + +<p>Watch expressions are expressions that are evaluated each time execution pauses. You can then examine the results of these expressions. These are useful in that they let you inspect invariants in your code that you know are there but aren't necessarily in the code ready for inspection. To add a watch expression, click in the box that says "Add watch expression" and enter a JavaScript expression whose output you'd like to monitor as you step through code.</p> + +<p>Then start running your code. The watch expression does nothing until you begin to step through your code, so nothing happens until you reach a breakpoint. At that point, a box showing your active watch expressions and their current values will appear:</p> + +<p><img alt="" src="https://mdn.mozillademos.org/files/7039/11-watch.png" style="display: block; margin-left: auto; margin-right: auto;">You can step through your code, watching the value of the expression as it changes; each time it does, the box will flash briefly yellow. You can remove a watch expression by clicking the "x" icon next to it, and, of course, you can have more than one watch expression at a time.</p> + +<h4 id="Highlight_and_inspect_DOM_nodes">Highlight and inspect DOM nodes</h4> + +<div class="geckoVersionNote"> +<p>This feature is new in Firefox 29.</p> +</div> + +<p>If you hover over a DOM node in the Variables pane, it will be highlighted in the page:</p> + +<p><img alt="" src="https://mdn.mozillademos.org/files/7073/25-highlight-node.png" style="display: block; margin-left: auto; margin-right: auto;">Also, a target icon will appear next to the variable<img alt="" src="https://mdn.mozillademos.org/files/7075/26-inspect%20node.png" style="display: block; margin-left: auto; margin-right: auto;">If you click on this target, the <a href="/en-US/docs/Tools/Page_Inspector">Inspector</a> will open with this DOM element selected.</p> + +<h3 id="Events_pane"><a name="events-pane">Events pane</a></h3> + +<div class="geckoVersionNote"> +<p>The events pane is new in Firefox 27.</p> +</div> + +<p>The events pane lists all DOM<span> events that currently have listeners bound from your code:</span></p> + +<p><img alt="" src="https://mdn.mozillademos.org/files/7041/12-events.png" style="display: block; margin-left: auto; margin-right: auto;">It shares its screen real estate with the <a href="#variables-pane">variables pane</a>, and you can use the tabs at the top of the pane to switch between them.</p> + +<p>It groups events by type. The screenshot above shows four types: Interaction, Keyboard, Mouse, and Navigation. Under each type it lists all events which have listeners in your code, with the following syntax:</p> + +<pre class="notranslate">[event name] on [event target] in [source file]</pre> + +<p>If you check the checkbox next to the event, the debugger will break at the first line of the event's listener. If you check the checkbox next to the event type, then the debugger will break for any of the events listed under that type.</p> + +<h2 id="How_do_I...">How do I...?</h2> + +<h3 id="Open_the_debugger">Open the debugger</h3> + +<p>To open the debugger, select "Debugger" from the Web Developer submenu in the Firefox Menu (or Tools menu if you display the menu bar or are on Mac OS X), or press Control-Shift-S (Command-Option-S on the Mac).</p> + +<h3 id="Find_a_source_file">Find a source file</h3> + +<p>When the debugger's open, all the JavaScript source files are listed in the <a href="#source-list-pane" title="#source-list-pane">source list pane</a>. You can browse the list to find the one you want, or search for a particular file using the <a href="#script filter" title="#script filter">script filter</a>.</p> + +<h3 id="Find_inside_a_file">Find inside a file</h3> + +<p>To find a function, search for a string, or jump to a line in a file open in the <a href="#source-pane" title="#source-pane">source pane</a>, you can use one of the special modifiers in the <a href="#script filter" title="#script filter">script filter</a>.</p> + +<h3 id="Set_a_breakpoint">Set a breakpoint</h3> + +<p>To set a breakpoint in a file open in the <a href="#source-pane" title="#source-pane">source pane</a>:</p> + +<ul> + <li>either click on the line number for the line you want to break at</li> + <li>or activate the context menu while on the line you want to break at, and select "Add breakpoint"</li> +</ul> + +<p>Each breakpoint is shown in two places in the debugger:</p> + +<ul> + <li>they're listed in the <a href="#source-list-pane" title="#source-list-pane">source list pane</a> underneath the file's name</li> + <li>the line in the source pane is marked with a blue circle</li> +</ul> + +<p>The screenshot below shows breakpoints at lines 3 and 10 of the file:</p> + +<p><img alt="" src="https://mdn.mozillademos.org/files/7043/13-set-a-breakpoint.png" style="display: block; margin-left: auto; margin-right: auto;"></p> + +<h3 id="Set_a_conditional_breakpoint">Set a conditional breakpoint</h3> + +<p>To set a conditional breakpoint, activate the context menu while on the line you want to break at, and select "Add conditional breakpoint". Then enter the conditional expression in the popup that appears:</p> + +<p><img alt="" src="https://mdn.mozillademos.org/files/7045/14-set-a-conditional-bp.png" style="display: block; margin-left: auto; margin-right: auto;">To edit the condition, or to add a condition to a normal breakpoint, activate the context menu and select "Configure conditional breakpoint":</p> + +<p><img alt="" src="https://mdn.mozillademos.org/files/7047/15-configure-conditional-bp.png" style="display: block; margin-left: auto; margin-right: auto;"></p> + +<h3 id="Disable_a_breakpoint">Disable a breakpoint</h3> + +<p>To disable a breakpoint:</p> + +<ul> + <li>either: uncheck the check box next to the breakpoint's entry in the <a href="#source-list-pane" title="#source-list-pane">source list pane</a></li> + <li>or: activate the context menu while your mouse pointer is over the breakpoint's entry in the source list pane, and select "Disable breakpoint"</li> +</ul> + +<h3 id="Disableenable_all_breakpoints">Disable/enable all breakpoints</h3> + +<div class="geckoVersionNote"> +<p>This feature is new in Firefox 29.</p> +</div> + +<p>To switch all breakpoints on or off, use the "Toggle all breakpoints" button in the <a href="/en-US/docs/Tools/Debugger#Source_list_pane">Source list pane</a>.</p> + +<h3 id="Break_on_a_DOM_event">Break on a DOM event</h3> + +<div class="geckoVersionNote"> +<p>This feature is new in Firefox 27.</p> +</div> + +<p>If you're listening to a particular DOM event, you can tell the debugger to break when the event is triggered without having to track down the listener and set a breakpont manually.</p> + +<p>First, open the <a href="#events-pane">events pane</a>: click the button in the <a href="#toolbar">toolbar</a> that opens the shared variables/events pane, then click the tab labeled "Events". The events pane will list all events for which you have assigned a listener:</p> + +<p><img alt="" src="https://mdn.mozillademos.org/files/7041/12-events.png" style="display: block; margin-left: auto; margin-right: auto;">Then check the box next to the event you want to break at.</p> + +<p>When the event is triggered the code will break at the start of your listener.</p> + +<h3 id="Step_through_my_code">Step through my code</h3> + +<p>When your code stops at a breakpoint, you can step through it using the four buttons on the left of the toolbar:</p> + +<p><img alt="" src="https://mdn.mozillademos.org/files/7049/16-stepping.png" style="display: block; margin-left: auto; margin-right: auto;">In order, the buttons are:</p> + +<ul> + <li>Play: run to the next breakpoint</li> + <li>Step over: advance to the next line in the same function.</li> + <li>Step into: advance to the next line in the function, unless on a function call, in which case enter the function being called</li> + <li>Step out: run to the end of the current function</li> +</ul> + +<h3 id="Use_a_source_map">Use a source map</h3> + +<p>JavaScript sources are often combined and minified to make delivering them from the server more efficient. Increasingly, too, JavaScript running in a page is machine-generated, as when compiled from a language like CoffeeScript. By using <a href="http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/" title="http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/">source maps</a>, the debugger can map the code being executed to the original source files, making debugging much, much easier.</p> + +<p>To tell the Debugger to use source maps if they are available, click the "<a href="#debugger-settings" title="#debugger-settings">Debugger settings</a>" button and select "Show original sources" from the list of settings that pops up:</p> + +<p><img alt="" src="https://mdn.mozillademos.org/files/7051/17-source-maps.png" style="display: block; margin-left: auto; margin-right: auto;">Of course, for this to work, you will need to have supplied a source map for the JavaScript running in the page. Do this by appending a comment directive to your source file:</p> + +<p><code>//# sourceMappingURL=http://example.com/path/to/your/sourcemap.map</code></p> + +<h3 id="Examine_variables">Examine variables</h3> + +<p>When the code has stopped at a breakpoint, you can examine its state in the <a href="#variables-pane" title="#variables-pane">variables pane</a> of the debugger:</p> + +<p><img alt="" src="https://mdn.mozillademos.org/files/7037/10-variables-pane.png" style="display: block; margin-left: auto; margin-right: auto;">Variables in global scope and in function, block, "with" scopes, etc. are listed separately, and you can expand objects to see their properties. You can also filter the variables shown using the "*" prefix in the <a href="#script filter" title="#script filter">script filter</a>:</p> + +<p><img alt="" src="https://mdn.mozillademos.org/files/7053/18-filter-variables.png" style="display: block; margin-left: auto; margin-right: auto;"></p> + +<h3 id="Modify_variables">Modify variables</h3> + +<p>When the code has stopped at a breakpoint, you can modify variables in the <a href="#variables-pane" title="#variables-pane">variables pane</a> of the debugger. Just click on the variable's current value and you'll be able to type there:</p> + +<p><img alt="" src="https://mdn.mozillademos.org/files/7055/19-modify-variable.png" style="display: block; margin-left: auto; margin-right: auto;"></p> + +<h3 id="Watch_an_expression">Watch an expression</h3> + +<p>You can watch the value of a JavaScript expression using the "<a href="#watch-expressions" title="#watch-expressions">Add watch expression</a>" function in the variables pane.</p> + +<h3 id="Debug_mobile_devices">Debug mobile devices</h3> + +<p>To learn how to debug mobile devices, see the guide to <a href="/en-US/docs/Tools/Remote_Debugging" title="/en-US/docs/Tools/Remote_Debugging">remote debugging</a>.</p> + +<h3 id="Black_box_a_source"><a name="black-box-a-source">Black box a source</a></h3> + +<p>In modern web development, we often rely on libraries like <a href="http://jquery.com/">jQuery</a>, <a href="http://emberjs.com/">Ember</a>, or <a href="http://angularjs.org/">Angular</a>, and 99% of the time we can safely assume that they “just work”. We don’t care about the internal implementation of these libraries: we treat them like a <a href="http://en.wikipedia.org/wiki/Black_box">black box</a>. However, a library’s abstraction leaks during debugging sessions when you are forced to step through its stack frames in order to reach your own code. With black boxing, you can tell the debugger to ignore the details of selected sources.</p> + +<p>In versions of Firefox before Firefox 27, you can black box a source by clicking the eyeball icon next to the source in the <a href="#source-list-pane">source list pane</a>:</p> + +<p><img alt="" src="https://mdn.mozillademos.org/files/6411/debugger-black-box-fx26.png" style="display: block; margin-left: auto; margin-right: auto;"></p> + +<p>From Firefox 27 onwards, enable or disable black boxing for a source by selecting the source in the <a href="#source-list-pane">source list pane</a> and clicking the eyeball icon at the bottom left:</p> + +<p><img alt="" src="https://mdn.mozillademos.org/files/7057/20-black-box.png" style="display: block; margin-left: auto; margin-right: auto;">You can black box several sources at once by opening the <a href="/en-US/docs/Tools/GCLI">developer toolbar</a> and using the <code>dbg blackbox</code> command:</p> + +<p><img alt="" src="https://mdn.mozillademos.org/files/5997/command.png" style="display: block; height: 48px; margin-left: auto; margin-right: auto; width: 537px;"></p> + +<p>When a source is black boxed:</p> + +<ul> + <li>Any breakpoints it may have are disabled.</li> + <li>When <a href="#debugger-settings">“pause on exceptions”</a> is enabled, the debugger won’t pause when an exception is thrown in the black boxed source; instead it will wait until (and if) the stack unwinds to a frame in a source that isn’t black boxed.</li> + <li>The debugger will skip through black boxed sources when stepping.</li> +</ul> + +<h3 id="Pretty-print_a_minified_file">Pretty-print a minified file</h3> + +<div class="geckoVersionNote"> +<p>Pretty-printing is new in Firefox 28.</p> +</div> + +<p>To pretty-print a file that has been minified, open the minified file and click the icon that contains a pair of braces:</p> + +<p><img alt="" src="https://mdn.mozillademos.org/files/7059/21-pp-before.png" style="display: block; margin-left: auto; margin-right: auto;">The file will now appear in a more readable format:</p> + +<p><img alt="" src="https://mdn.mozillademos.org/files/7061/22-pp-after.png" style="display: block; margin-left: auto; margin-right: auto;">From Firefox 29 onwards, you can instruct the debugger to detect minified sources and pretty-print them for you automatically, by selecting "Auto Prettify Minified Sources" in the <a href="/en-US/docs/Tools/Debugger#Debugger_settings">Debugger settings</a>.</p> + +<h3 id="Access_debugging_in_add-ons">Access debugging in add-ons</h3> + +<p>The following items are accessible in the context of chrome://browser/content/debugger.xul (or, in version 23 beta, chrome://browser/content/devtools/debugger.xul):</p> + +<ul> + <li>window.addEventListener("Debugger:EditorLoaded") - called when the read-only script panel loaded.</li> + <li>window.addEventListener("Debugger:EditorUnloaded")</li> +</ul> + +<p>Relevant files:</p> + +<ul> + <li>chrome://browser/content/devtools/debugger-controller.js</li> + <li>chrome://browser/content/devtools/debugger-toolbar.js</li> + <li>chrome://browser/content/devtools/debugger-view.js</li> + <li>chrome://browser/content/devtools/debugger-panes.js</li> +</ul> + +<p>Unfortunately there is not yet any API to evaluate watches/expressions within the debugged scope, or highlight elements on the page that are referenced as variables in the debugged scope. (currently a work in progress, see bug <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=653545" title="https://bugzilla.mozilla.org/show_bug.cgi?id=653545">653545</a>.)</p> + +<h2 id="Keyboard_shortcuts">Keyboard shortcuts</h2> + +<p>{{ Page ("en-US/docs/tools/Keyboard_shortcuts", "debugger") }}</p> + +<h3 id="Global_shortcuts">Global shortcuts</h3> + +<p>{{ Page ("en-US/docs/tools/Keyboard_shortcuts", "all-toolbox-tools") }}</p> diff --git a/files/pt-br/tools/debugger/set_a_logpoint/index.html b/files/pt-br/tools/debugger/set_a_logpoint/index.html new file mode 100644 index 0000000000..0a9b75f07d --- /dev/null +++ b/files/pt-br/tools/debugger/set_a_logpoint/index.html @@ -0,0 +1,53 @@ +--- +title: Set a logpoint +slug: Tools/Depurador/Set_a_logpoint +translation_of: Tools/Debugger/Set_a_logpoint +--- +<p>{{ToolsSidebar}}</p> + +<p>As vezes você quer ver um valor em seu código mas sem pausar a execução dele. Ao enves de encher seu código com vários console.log, você pode usar o novo tipo de breakpoint adicionado ao Firefox 67, o logpoint. Logpoints mostram uma mensagem no console sem a necessidade de pausar a execução do código.</p> + +<p><font color="#000000" face="Arial"><span style="font-size: 14.6667px; white-space: pre-wrap;">O logpoint é especialmente util em casos onde parar a execução também quebrará a execução da reprodução de testes, como quando se está debugando uma janela popup, ou executando uma focus-related logic.</span></font></p> + +<p>Para criar um logpoint:</p> + +<ol> + <li><font color="#000000" face="Arial"><span style="font-size: 14.6667px; white-space: pre-wrap;">Clique com o direitro em uma linha no painel de Debug e selecione<strong> Add log </strong>do context menu.</span></font></li> +</ol> + +<p><span style="background-color: transparent; color: #000000; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><img alt="" src="https://mdn.mozillademos.org/files/16601/add_logpoint.png" style="display: block; height: 121px; margin: 0px auto; width: 241px;"></span></p> + +<ol start="2"> + <li><span id="docs-internal-guid-5f0d040f-7fff-0163-73d5-1dee8cb97d31" style="background-color: transparent; color: #000000; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">Crie uma expresão inline. O resultado irá ser apresentado no console, toda vez que encontrar os logpoints. Você pode usar qualquer variável ou funcção disponível no escopo atual.</span></li> +</ol> + +<p><span style="background-color: transparent; color: #000000; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;"><img alt="" src="https://mdn.mozillademos.org/files/16646/creating_the_log_point.png" style="border: 1px solid black; display: block; height: 67px; margin: 0px auto; width: 312px;"></span></p> + +<h2 id="Trabalhando_com_logpoints">Trabalhando com logpoints</h2> + +<p>Quando você set um logpoint, o indicador é roxo, ao enves de azul de um incondicional breakpoint ou laranja de um condicional breakpoint.</p> + +<p>Você pode ver a lista de logpoits no painel lateral de Breakpoints.</p> + +<p><img alt="" src="https://mdn.mozillademos.org/files/16645/list_logpoints.png" style="border: 1px solid black; display: block; height: 134px; margin: 0px auto; width: 845px;"></p> + +<p>Quando seu código encontra um logpoint, a mensagem que você definiu ira ser apresentada no console. Vou pode fazer isso facilmento vendo a mensagem abrindo um console dividido sob o debug. (Ou pressione s <kbd>Esc</kbd> ou selecione o menu elipsis (...) e clique em <strong>Show Split Console.</strong>)</p> + +<p><img alt="" src="https://mdn.mozillademos.org/files/16644/logpoints.png" style="border: 1px solid black; display: block; height: 370px; margin: 0px auto; width: 915px;"></p> + +<h3 id="Quando_devo_usar_logpoints">Quando devo usar logpoints?</h3> + +<ul> + <li>Quando você quer saber se uma linha de código específica foi executada, mas sem parar a execução do código, insira um logpoint.</li> + <li>Logpoints são bastante uteis para mostrar o valor de uma variável em um ponto específico do código. É mais rápido alterar o código fonte subjacente para adicionar chamadas do que o método <code>console.log.</code></li> + <li>Se você precisa executar uma lógica adicional no código fonte e não pode muda-lo você mesmo, você pode usar um logpoint.</li> +</ul> + +<h2 id="Veja_também">Veja também</h2> + +<ul> + <li><a href="/en-US/docs/Tools/Debugger/How_to/Set_a_breakpoint">Set a breakpoint</a></li> + <li><a href="/en-US/docs/Tools/Debugger/How_to/Set_a_conditional_breakpoint">Set a conditional breakpoint</a></li> + <li><a href="/en-US/docs/Tools/Debugger/Set_an_XHR_breakpoint">Set an XHR breakpoint</a></li> + <li><a href="/en-US/docs/Tools/Debugger/How_to/Disable_breakpoints">Disable breakpoints</a></li> +</ul> |