Traceback (most recent call last): File "<stdin>", line 12 IndentationError: unindent doesn't match any outer indent level - led

from machine import Pin, PWM
from time import sleep
pwm = PWM(Pin(15))
pwm.freq(1000)
while True:
for duty in range(65025):
pwm.duty_u16(duty)
sleep(0.0001)
for duty in range(65025, 0, -1):
pwm.duty_u16(duty)
sleep(0.0001)

If the code you've posted here is exactly what you are trying to run on your MicroPython board then the problem is that you've used a mixture of spaces and tab characters to indent different lines. You need to stick to either one or the other - the standard for Python is to use four spaces for each level of indentation.
Check the settings of whatever program you are using to edit your code to see if you can change what happens when you press the tab key. If you're copying and pasting code from a web page or elsewhere, you need to check how it's indented and make it consistent with your own code and editor.

Related

Eclipse (Code Composer Studio) - Preprocessor Macros not shown after 5000 lines of code?

I'm using the Code Composer Studio from Texas Instruments for a microcontroller application. This is an eclipse based environment. Now there is a file, which has more than 5000 lines of code and it does not show the precompiler macros (the #if/#else case is can not be distinguished, because the background is white for both). When I reduce the code to less than 5000 lines, it shows everything correctly.
So, is there a setting somehwere, where I can choose the maximum number of lines before it compresses? (I had a question once when I open a large file about that, but now it never shows it again).
This setting is "scalability": Window-> Preferences->C/C++-> Editor->Scalability.
There are checkboxes for things to disable in large files (live parsing, syntax coloring etc) and how large a file must be to trigger these limitations. The default usually is 5000 lines.

Debugger (C) steps into stdio.h library, how do i prevent that?

I have a "problem" about my debugger.
When I debug, I usually use the command step into, to go forward, and everything was going smooth. Then some day, when I stepped into a function like printf(), or fscanf(), the debugger started taking me into the actual library, <stdio.h>...
I know I can avoid this just using the command step over, but I'm really used to debug my code easily and fast, just by pressing constantly the same button, and I don't want to switch every 3 seconds from step into to step over, because I want to focus on my code flow...
Can anyone help me please?
If you need other info, of course I'm going to give them to you.
As you have tagged Visual Studio Code, I am answering for the debugger in that IDE. To execute and then leave a function you have entered while debugging, you can press SHIFT F11. (This would in effect be "the opposite" of entering a function, which is F11.) From the Microsoft documentation a description of Step Out can be found:
"Click Step Out on the Debug menu to resume running on the target.
This command executes the rest of the current function and breaks when
the function return is completed."
You can use ~/.gdbinit configuration file, see man gdbinit
skip file /usr/include/stdio.h
You can check it in gdb using info skip:
(gdb) info skip
Num Enb Glob File RE Function
1 y n /usr/include/stdio.h n <none>
(gdb)
You can skip a whole file skip file /what/ever.c or a function : skip printf

Eclipse CDT: Mapping console output to source file and line

While debugging code it helps to have source filename and line number on console output. I already use FILE and LINE macros. But it would be great if double clicking a line in the console output would take me to the exact source line which was responsible for outputting that line of log. Can eclipse parse console output and do something like this? It need not work all the time, only when the log line is in a specific format and the source filename and line number are valid.
It's possible to use a workaround if you add the pydev plugin and a few lines of python to call your main function. You can find the needed code here: https://github.com/oct15demo/python_calls_cpp
As noted there, I posted a query on the Eclipse forum to find out the status of any ongoing effort or obstacles to implement within Eclipse.
I could not find out any further information on the feature, if it's there, it's well hidden.
Update March 17, 2022, I shall be working on the feature for Eclipse, don't have an estimate of time yet.

Emacs now defaults to 2-space soft tabs?

I haven't used Emacs in years, and trying a fairly new one (23.4.1 on Linux) I notice that the mixed tab style I remember seems to no longer be the default indentation. It used to have 4 spaces as the first tab level, then a tab as the next tab level, then a tab plus four spaces, etc etc. I am editing a .c file.
Does Emacs still do this by default at all or are such defaults a thing of the past and is it now much easier to use Emacs for those of us who use hard tabs or soft tabs but never mixed tabs and who use 2-space tabs in some cases and 4-space in others?
UPDATE 2: Actually it's not doing 2-space soft tabs exactly, but rather once I get to the magic number of 8 spaces, then it sticks in a tab just as it always did before. So no big change and this mixed tab business is apparently still in full effect just as #legoscia says!
UPDATE: I've tried this now on three systems - Emacs v25.x on Windows 7, v24.x on Ubuntu 12.x, and v23.x on Xubuntu 15.x and all of them are doing 2-space soft tabbing when I'm in "c-mode." My question is about the defaults and how they've changed over the last let's say 5 years.
That's still what Emacs does by default: each level of indentation is 4 spaces, tabs are considered to be 8 spaces wide, and Emacs uses the minimum amount of tabs and spaces to make up the indentation for each line.
This is affected by the following variables:
indent-tabs-mode: this defaults to t. If it is nil, Emacs uses only spaces to indent to the desired depth.
tab-width: this defaults to 8. This affects how wide Emacs thinks a tab is.
c-basic-offset et al. This determines the indentation step for each level in C files (also C++, Java and other languages using modes based on cc-mode). Often you'll want to type C-c . to use a set of settings for a particular indentation style instead.
Usually you want to set these variables individually for a certain file or for a certain project. To set them for a single file, you can include a magic comment to set "file variables". To set variables for every file in a directory and its sub-directories, place a .dir-locals.el file in the root directory of the project, and specify per-directory local variables.
One thing that Emacs doesn't directly support is the notion of using tabs exclusively for indentation. You could emulate this by setting c-basic-offset (or the corresponding variable for other languages) and tab-width to the same value, but you might be better served by Smart Tabs, as Carsten suggested in the comments.
Adding this to my .emacs file did the trick:
(setq-default tab-width 4)
(setq-default indent-tabs-mode nil)
(setq-default c-basic-offset 4)

Windbg stacktrace shows line numbers before or after macro expansion

I have a C file with several macros.
The exe generated from the file crashes several times reporting events in the Windows event viewer. Upon taking a dump of the process and analyzing it using WinDbg with the correct pdb files for the symbols, we get the stacktrace and know the function which is causing the problem.
The stacktrace shows the line number of our function code which called other functions one of which led to the crash-
08 msvcr80!fwrite(void * buffer = 0x00000000`01ded180, unsigned int64 size =
0x1fff38, unsigned int64 count = 0x524fe123, struct _iobuf * stream =
0x00000000`00000000)+0x5f [f:\dd\vctools\crt_bld\self_64_amd64\crt\src\fwrite.c
# 77]
09 <function name>(void * param = 0x00000000`02d15a00)+0xb02
[<path to file> # 1516]
Our function called fwrite, which is shown to be at line 1516. However, there is no call to fwrite at 1516. (The crash happens because the stream argument to fwrite is 0x0)
I was wondering if these line numbers correspond to the source file after the macros are expanded ? What could be the reason for a possibly wrong line number ?
EDIT : The exe here is a debug build and was compiled with optimizations disabled.
I loaded the dump again in WinDbg but also linked in the source file to WinDbg itself this time. It points to line 1516 and upon viewing that in the source from WinDbg, it points to a line where there is no call to fwrite. However, there is such a call a few lines above.
Well i do not have direct answer to question here :(
But i would make a COD file. a file that maps source code to assembly code. Then see the assembly code generated for the function of interest. Specifically related to line 1516.
Am hoping that would give a fair insight as to whats going on behind the scene. You may want to give a quick try.
You just need to turn on a compiler flag to generate COD file. More can be read here

Resources