See if your toolset implements the divide by zero handling in the same way as ARM's toolset does it's likely that it does something at least similar.
Post Mortem
If so, you can install a handler that gets called when the problem occurs and you can printf registers and stack so that you can determine where the problem is occurring. A possible similar alternative is that your small Linux distro is throwing a signal you can catch. I'm not sure how you're getting your information that a divide by zero is occurring, but if it's because the runtime is spitting out a message to that effect, you always have the option of finding out where that is handled in the runtime, and replacing it with your own more informative message.
However, I'd guess that there's a more 'architected' way to get your code to run a signal handler or ARM's technique. You should use this as an excuse to invest in improving the debug-ability of your device - for both this problem and future issues. Even if you can't get live debugging, you should be able to find a way to generate and save off core dumps for post-mortem debugging pinpointing the source or any unhandled exception immediately. It is a commercial product but there is a 30 money back guarantee. Usually the exception will be handed a structure that contains the address that caused the exception and other information.
Why dividing by zero is undefined
You will probably have to become familiar with the microcontroller's datasheet or RTOS manual. Use the -save-temps for gcc and find the relevant assembly for division in the generated. If you're lucky it will be something fairly distinctive, possibly even a function call. If it's a function call you can use weak linking to override it with your own checked version. The exception already has the address location of the offending divide by zero code.
Navigation menu
Your OS should pass this information along I assumes that is how you know it is divide by zero. Print the address and go look in your code. If you can print a stack trace it would be even easier to solve. Another option would be to check the differences in your version control software between the last know working version and the first non working version. This should give you a limmited change set within which to search for the problem.
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service , privacy policy and cookie policy , and that your continued use of the website is subject to these policies. Finding division by zero in a big project Ask Question. Another approach might be to search the binary for the division opcodes, and then work backwards to the source code using the map file. Michael Burr k 40 These devices are often seriously constrained by hardware requirements.
Improving the debugability is not usually feasible. Using a dump could help find one division bug. Examining all the divisions in the product might find more. Sadly I never had much luck with emailing e. And because of that, any non-zero number, divided by zero, is left just "undefined. Negative 1 divided by 0.
To report this review as inappropriate, please complete this short form.
We say all of these things are just "undefined. So let's do that right now. We could just take the simplest of all non-zero numbers.
- Die Jugendgerichtshilfe § 38 JGG (German Edition)?
- Division by zero.
- Division by zero;
- A Very English Hero: The Making of Frank Thompson.
- Why dividing by zero is undefined (video) | Khan Academy!
- Division By Zero: 1 (Post Mortem) by Haley Brown (eBook) - Lulu.
- Blanca de Borbón (Spanish Edition).
We'll just do it with one. But we could have done this with any non-zero number. Let's take the example of one. Since we don't know what it means-- or we're trying to figure out what it means to divide by zero Lets just try out really, really, small positive numbers.
Let's divide by really, really small positive numbers and see what happens as we get close to zero. So lets divide by 0. If we divide 1 by 0.
c++ - Finding division by zero in a big project - Stack Overflow
If I go really, really close to zero. If I divide 1 by 0. This is a millionth.
So we see a pattern here. As we divide one by smaller and smaller and smaller positive numbers, we get a larger and larger and larger value. Based on just this you might say, well, hey, I've got somewhat of a definition for 1 divided by 0.
Maybe we can say that 1 divided by 0 is positive infinity. As we get smaller and smaller positive numbers here, we get super super large numbers right over here. But then, your friend might say, well, that worked when we divided by positive numbers close to zero but what happens when we divide by negative numbers close to zero?
So lets try those out. Well, 1 divided by negative 0.