First issue: gdb runs but you can't step through the code.
Solution: gdb allocated too many breakpoints, and HW breakpoint is necessary for single stepping. Delete all breakpoints.
Second issue: gdb runs, but code never gets to main. seems to be stuck in the flash loader
Solution: code was not stuck in the flashloader, but in infinite loop of "abort()" within a static C++ constructor.
Things that were helpful:
set verbose on
in gdb start-up script (Project Properties -> Run/Debug Settings -> Startup Scripts -> Debug)
Also, comment out continue at end of script
#continue
so that debugger starts right after it loads the code. Also, replace "abort()" with https://github.com/scottt/debugbreak
Monday, July 28, 2014
Monday, February 13, 2012
Wrangling Setup (msi) projects
To add a custom action to a Setup/Deployment project, you can write a stand alone script (in VBS), or write a standalone executable, or you can add an Installer class to your main application. I like the last one, since it keeps everything together in less files.
1. Add an "Installer Class" to your project using the Add New Item
2. Override the 4 class: Install, Commit, Uninstall, Rollback.
3. If you want to do any logging, use
4. If you want to use passed parameters, use
5. Build
6. Add the application as a Custom Action to your setup project. Add it to ALL 4 actions, otherwise you'll get an obscure error.
7. To pass parameters, use CustomActionData field, and format it like
8. You can make it conditional by
a. adding a Checkbox to the user interface, and naming the property of the checkbox, ie DO_WHAT_I_WANT
b. Using that checkbox name (ie DO_WHAT_I WANT) as the Conditional of the custom action.
9. To debug, Use
where you need it.
1. Add an "Installer Class" to your project using the Add New Item
2. Override the 4 class: Install, Commit, Uninstall, Rollback.
3. If you want to do any logging, use
this.Context.LogMessage(string)4. If you want to use passed parameters, use
Context.Parameters5. Build
6. Add the application as a Custom Action to your setup project. Add it to ALL 4 actions, otherwise you'll get an obscure error.
7. To pass parameters, use CustomActionData field, and format it like
/name=value /name=value. Use double quotes if you have spaces in the values.8. You can make it conditional by
a. adding a Checkbox to the user interface, and naming the property of the checkbox, ie DO_WHAT_I_WANT
b. Using that checkbox name (ie DO_WHAT_I WANT) as the Conditional of the custom action.
9. To debug, Use
System.Diagnostics.Debugger.Launch();System.Diagnostics.Debugger.Break();where you need it.
Tuesday, February 7, 2012
Stack size of bootloader versus application
I got myself in a bind when I changed the stack size of my application, but didn't change the size of the stack in the bootloader.
I learned something new today: the CPU sets the stack pointer to the first word of the vector table on reset. If you have a bootloader that does something like jump to the reset vector (__vector_table + 4 bytes), it will NOT reload the stack pointer. If your stack pointer is not changed, you are likely to start writing all over the stack with your static variables. yuck.
In my case, the bootloader had a stack of 0xC00. My main app was running out of memory, so I changed the stack to 0xB80 (which was more than enough). However, I noticed that my app was still using a stack of size 0xC00, when it had only allocated 0xB80 to it. uhoh.
To fix this, I added these 2 lines to the ResetHandler in startup_stm32f10x_md_vl.s (or the equivalent for other STM32s)
Btw, IAR 6.3 has a feature to analyze the stack size. It kinda works, but it is a pain in the butt if you have C++ virtual functions or any function pointers.
I learned something new today: the CPU sets the stack pointer to the first word of the vector table on reset. If you have a bootloader that does something like jump to the reset vector (__vector_table + 4 bytes), it will NOT reload the stack pointer. If your stack pointer is not changed, you are likely to start writing all over the stack with your static variables. yuck.
In my case, the bootloader had a stack of 0xC00. My main app was running out of memory, so I changed the stack to 0xB80 (which was more than enough). However, I noticed that my app was still using a stack of size 0xC00, when it had only allocated 0xB80 to it. uhoh.
To fix this, I added these 2 lines to the ResetHandler in startup_stm32f10x_md_vl.s (or the equivalent for other STM32s)
Reset_Handler
;; MTL
;;force reload of the stack pointer!
;; it is stored on the start of the vector table
LDR R0,=__vector_table
LDR SP,[R0]
;;
LDR R0, =SystemInit
BLX R0
LDR R0, =__iar_program_start
BX R0
Btw, IAR 6.3 has a feature to analyze the stack size. It kinda works, but it is a pain in the butt if you have C++ virtual functions or any function pointers.
Monday, February 6, 2012
How to add options to a Setup and Deployment project in Visual Studio
Visual Studio has a "Setup and Deployment" project, that is mostly easy to set up with a bunch of clicks.
If you want to customize the installer (with options for the user), you need to write little programs to do each custom operation.
The scripts can be written as *.exe or *.dll files, which need to be compiled. That seems a bit overkill.
The scripts can also be written as VBS (Visual Basic Scripting) language. For someone like me, I don't want to know about VBS, but that's the only other option you have. VBS is not the same as VB, but it is similar. In addition, some of the default assemblies you have access to in VBS from the command line are not available from the Setup Project.
To test out a VBS script, you run the 'cscript' command from the command line, or double click it.
Here's a VBS script that opens a firewall. You add the script to the Custom Action -> Commit, and change the CustomActionData property to
You can make it conditional by adding something to the UserInterface (say Checkboxes (A)), name the property name of that checkbox, and then use that in a conditional for the custom action. Sorry that's vague, but should give me some hints when I actually need to implement it.
If you want to customize the installer (with options for the user), you need to write little programs to do each custom operation.
The scripts can be written as *.exe or *.dll files, which need to be compiled. That seems a bit overkill.
The scripts can also be written as VBS (Visual Basic Scripting) language. For someone like me, I don't want to know about VBS, but that's the only other option you have. VBS is not the same as VB, but it is similar. In addition, some of the default assemblies you have access to in VBS from the command line are not available from the Setup Project.
To test out a VBS script, you run the 'cscript' command from the command line, or double click it.
Here's a VBS script that opens a firewall. You add the script to the Custom Action -> Commit, and change the CustomActionData property to
[TARGETDIR]. There a bunch of variables you can pass in CustomActionData, but I've yet to find a complete list of them online.You can make it conditional by adding something to the UserInterface (say Checkboxes (A)), name the property name of that checkbox, and then use that in a conditional for the custom action. Sorry that's vague, but should give me some hints when I actually need to implement it.
Dim target
'msgbox "start"
'msgbox Session.Property("CustomActionData")
target = Session.Property("CustomActionData")
'msgbox target
Set objFirewall = CreateObject("HNetCfg.FwMgr")
Set objPolicy = objFirewall.LocalPolicy.CurrentProfile
filename = target & "cog-trk-db-service.exe"
'msgbox filename
Set objApplication = CreateObject("HNetCfg.FwAuthorizedApplication")
objApplication.Name = "cog-trk-db-service"
objApplication.IPVersion = 2
objApplication.ProcessImageFileName = filename
objApplication.RemoteAddresses = "*"
objApplication.Scope = 0
objApplication.Enabled = True
Set colApplications = objPolicy.AuthorizedApplications
colApplications.Add(objApplication)
msgbox "Firewall exception created for " & filename
'msgbox "stop"
STM32 fault handling
http://blog.frankvh.com/2011/12/07/cortex-m3-m4-hard-fault-handler/
Here is the IAR version of the asm.
http://blog.frankvh.com/2011/12/07/cortex-m3-m4-hard-fault-handler/
Here is the IAR version of the asm.
NAME HardFault_Handler
AAPCS BASE,INTERWORK
PRESERVE8
REQUIRE8
EXTERN hard_fault_handler_c
SECTION .text:CODE:REORDER(2)
THUMB
PUBLIC HardFault_Handler
PUBLIC BusFault_Handler
HardFault_Handler
BusFault_Handler
TST LR, #4
ITE EQ
MRSEQ R0, MSP
MRSNE R0, PSP
B hard_fault_handler_c
END
Tuesday, June 28, 2011
Learning about SQL
There are more than one way to do queries in SQL in .NET. I'm summarizing them here for my own use:
- SqlReader - reads one line of a table at a time, after a SELECT statement is made
- SqlDataAdapter -still learning about this. appears to be a magic box where things just happen.
- Linq - DataContext - uses high level LINQ statements to do the query. Has the advantage of mostly keeping things tightly typed. Has the disadvantage that it doesn't do generic SQL commands (like add a new column to a table).
Friday, June 11, 2010
C# example of directly getting the local time from a Domain Controller
In case you need to get the current time (appears to be UTC) from a trusted source rather than rely on the local computer to report the time (which can be easily changed), this snippet gives guidance. You can get the name of a domain controller from the LOGONSERVER environment variable.
using System.DirectoryServices.ActiveDirectory;
DirectoryContext context = new
DirectoryContext(DirectoryContextType.DirectoryServer, "insert_domain_controller_name_here");
DomainController dc =
DomainController.GetDomainController(context);
DateTime dt = dc.CurrentTime;
MessageBox.Show("Domain Time is " +
dt.ToLongTimeString());
Subscribe to:
Comments (Atom)