How to debug "Collection was mutated while being enumerated" errors and like, when Xcode does not provide me with enough information? - xcode

Currently, I see a recurring error:
2013-04-18 02:35:51.583 aaah[1713:1110f] *** Terminating app due to uncaught exception 'NSGenericException', reason: '*** Collection <__NSArrayM: 0x1fc00dc0> was mutated while being enumerated.'
In the failing background queue (I see my queues state upon the moment of a crash by pressing Command + 5) I see:
0 _pthread_kill
1 pthread_kill
And I see assembly output which I completely don't understand.
I know how to resolve this kind of array enumeration errors - I just can't understand where/how I should seek for the piece of code causing my app to crash.
I have much multi-threaded code using AFNetworking and Core Data, so I can't just remember where the crucial section might be.
Also, this error occurs not always, but from time to time, so it is difficult just to use "isolation approach", isolating smaller and smaller pieces of code, to finally identify the buggy piece of code.
So the question is:
How can I extract some more useful information from this output, or Xcode can provide me with some more verbosity level, so I could know how to resolve this annoying piece of code.

Have you tried setting an exception breakpoint? Sometimes the debugger struggles with exception handling inside blocks but it might help.
In the breakpoints navigator (one of the tabs on the left side of the window) click the plus button at the bottom of the window and select add an exception breakpoint. Then hit done.
Now when you crash, the debugger should hopefully put you right before the instant the exception was raised.
See http://developer.apple.com/library/mac/#recipes/xcode_help-breakpoint_navigator/articles/adding_an_exception_breakpoint.html for more info.
Edit:
Based on the feedback provided in the comments, here's some more analysis:
The exception your application is raising means that you attempted to change a collection type (in this case, an NSMutableOrderedSet) inside of an enumeration block (in your case, most likely a for-loop). It looks like you're trying to remove objects in a set that you are looping over: [NSMutableOrderedSet removeObjectsInRange:inOrderedSet:]
To resolve this you should store the ranges you wish to remove and then do the actual removing once you're no longer iterating over the set. It's still going to be difficult since, as I understand it, you're not breaking inside of Objective-C code. You should look at the running threads in the panel on the left and look at what method they're currently in. That might give you a hint as to where your code is wrong.

Related

Need help selecting an item from a dropdown list in HP UFT

I need some help with selecting a value from a dropdown list. The dropdown is a WebElement, and the flow works well up to the point where the value should be selected.
My code is as follows:
.Browser("Browser").Page("PageName").WebElement("DropDownList").Click
.WebList("ListOfItems").Select(itemToSelect)
Note: itemToSelect is the name of the item that needs to be selected from the list, which is being passed as a parameter within the function.
When running the code, I get an unspecified error.
The weird thing is that before the error is thrown, I can see the value being selected from the list in the browser, as upon selecting it, some fields in the form change. Also, if I press "Skip" in the error message panel, the process goes on as if nothing happened.
I am certain the error comes from .WebList("ListOfItems").Select(itemToSelect) but I do not know what to do in order to fix it.
Try this code.It works for me.
StrAllItems = Split(Browser("name:=.*").Page("title:=.*").WebList("name:=.*").GetRoProperty("all items"),";")
For intCounter = Lbound(strAllItems) to Ubound(strAllItems)-1
If Browser("name:=.*").Page("title:=.*").WebList("name:=.*").GetItem(intCounter)= "SomeValue" Then
Browser("name:=.*").Page("title:=.*").WebList("name:=.*").Select (intCounter)
Exit For
End If
Next
Please let me know if this help.
If the test behaves correctly and you're just getting an superfluous error you can just ignore this specific error. It's best of course to understand where the error comes from, you should probably contact MicroFocus support but in the meantime you can turn off error handling for the offending line.
Browser("Browser").Page("PageName").WebElement("DropDownList").Click
On Error Resume Next ' turn off error handling
Browser("Browser").Page("PageName").WebList("ListOfItems").Select(itemToSelect)
On Error Goto 0 ' turn error handling back on
BTW, I changed your code a bit to make it valid, I assume this is what your code really looks like.
Possible timing issue: You might need to wait for the hole list to appear before you select the item.
Often, the item exists, but the app is still updating its GUI.
Whenever you access the GUI with UFT while the app is not idle (f.e. not ready for user input because it is still updating its HTML), you might get all kinds of strange results, including unexpected errors, hangs, instability.
So how do you wait for the list to be complete? I don't know, because it heavily depends on the way your app is refreshing its GUI. You need to explore that, and integrate some synchronization code that waits for the right condition to be met.
Unfortunately, this is a hell of a job sometimes.
A suitable workaround (and a good way to verify if my hyphothesis is correct) might be to insert a large delay between the first click and the list item selection click. (A quick way to do a similar thing is to single-step through the code.) If that does not generate any error or issues, you can be pretty sure it is what I describe, and you can experiment with lower delay durations to find a good value.
Thanks to everyone for your replies.
The issue turned out to be due to the object not being added well to the repository.
It was eventually fixed by adding it properly.

More specific OpenGL error information

Is there a way to retrieve more detailed error information when OpenGL has flagged an error? I know there isn't in core OpenGL, but is there perhaps some common extension or platform- or driver-dependent way or anything at all?
My basic problem is that I have a game (written in Java with JOGL), and when people have trouble with it, which they do on certain hardware/software configurations, it can be quite hard to trace down where the root of the problem lies. For performance reasons, I can't keep calling glGetError for each command but only do so at a few points in the program, so it's kind of hard to even find what command even flagged the error to begin with. Even if I could, however, the extremely general error codes that OpenGL have don't really tell me all that much about what happened (seeing as how the manpages on the commands even describe how the various error codes are reused for sometimes quite many different actual error conditions).
It would be tremendously helpful if there were a way to find out what OpenGL command actually flagged the error, and also more details about the error that was flagged (like, if I get GL_INVALID_VALUE, what value to what argument was invalid and why?).
It seems a bit strange that drivers wouldn't provide this information, even if in a completely custom way, but looked as I have, I sure haven't found any way to find it. If it really is that they don't, is there any good reason for why that is so?
Actually, there is a feature in core OpenGL that will give you detailed debug information. But you are going to have to set your minimum version requirement pretty high to have this as a core feature.
Nevertheless, see this article -- even though it only went core in OpenGL 4.3, it existed in extension form for quite some time and it does not require any special hardware feature. So for the most part all you really need is a recent driver from NV or AMD.
I have an example of how to use this extension in an answer I wrote a while back, complete with a few utility functions to make the output easier to read. It is written in C, so I do not know how helpful it will be, but you might find something useful.
Here is the sort of output you can expect from this extension (AMD Catalyst):
OpenGL Error:
=============
Object ID: 102
Severity: Medium
Type: Performance
Source: API
Message: glDrawElements uses element index type 'GL_UNSIGNED_BYTE' that is not
optimal for the current hardware configuration; consider using
'GL_UNSIGNED_SHORT' instead.
Not only will it give you error information, but it will even give you things like performance warnings for doing something silly like using 8-bit vertex indices (which desktop GPUs do not like).
To answer another one of your questions, if you set the debug output to synchronous and install a breakpoint in your debug callback you can easily make any debugger break on an OpenGL error. If you examine the callstack you should be able to quickly identify exactly what API call generated most errors.
Here are some suggestions.
According to the man pages, glGetError returns the value of the error flag and then resets it to GL_NO_ERROR. I would use this property to track down your bug - if nothing else you can switch up where you call it and do a binary search to find where the error occurs.
I doubt calling glGetError will give you a performance hit. All it does is read back an error flag.
If you don't have the ability to test this on the specific hardware/software configurations those people have, it may be tricky. OpenGL drivers are implemented for specific devices, after all.
glGetError is good for basically saying that the previous line screwed up. That should give you a good starting point - you can look up in the man pages why that function will throw the error, rather than trying to figure it out based on its enum name.
There are other specific error functions to call, such as glGetProgramiv, and glGetFramebufferStatus, that you may want to check, as glGetError doesn't check for every type of error. IE Just because it reads clean doesn't mean another error didn't happen.

vs2012 debugger hangs while i want to expand some collection variable

I'm debugging a project using VS2012 ultimate, but encountered this problem very often now. usually it happens when i want to expand a collection type value(e.g, List<>, Dictionary<> and so on) to watch its value. It just failed to show the value and then hangs forever, the error message is like
"Function evaluation disabled because a previous function evaluation timed out. You must continue execution to reenable function evaluation." the only thing i could do is to restart the debugger.
can anybody give some help?
When you expand a value in the debugger to see its members, the debugger does somethings called a "func-eval" behind the scenes, which basically means it 'wakes up' one of the the threads in the debuggee and runs some code in it in order to display its result. This is usually either executing a property's getter or an object's .ToString() method.
Sometimes, the evaluation can take too long (often because a property getter gets stuck waiting on some lock that is held by another thread, in which case, you could keep waiting forever and it'll never return, because all threads except the thread that's doing the func-eval are paused by the debugger). In these cases, after a short while the debugger will decide to 'give up' and display the message you've encountered. You don't have to restart your app to try evaluating properties again - you can simply do another Step Over (F10).
As a more permanent solution, you can do one of two things:
Go into Tools->Options->Debugging->General and disable "Enable property evaluation and other implicit function calls". This will make the debugger's display a lot less useful as you will only be able to view fields, but it guarantees you will never get stuck and receive the timeout message.
Try to figure out which property in which object is the one that keeps timing-out. This can be a bit tricky, by try paying attention to which objects you are viewing when this happens - the timeout will usually occur just after you scroll down to the offending property. Once you know which property is at fault, either change it into a method, or put [DebuggerBrowsable(DebuggerBrowsableState.Never)] above it to prevent the debugger from displaying it.

An error occurred while executing the command definition. See the inner exception for details. MVC3

im getting this error
but I have no idea why its happening. It stops happening when I restart visual studio, but after a while, it happens again. Its weird, since it happens just right after logging in. It makes me think that I left a connection open or there is something else going on. You guys have any idea of what could it be?
Hard to tell without knowing your project. But it may have to do with executing code in a setter, which is generally seen as an anti-pattern. (As an aside: the reason for that is that a setter suggests that you only change that little piece of the object's state, without side effects). An improvement would be to loop through ProjectList not sooner than when the ProjectExtensionList is addressed.
If setting the value for ProjectList is part of the materialization of its containing object (DashboardModel) the loop may cause a database read that has to wait for a connection that is involved in reading values for DashboardModels. If you defer the looping until when it is really necessary, at that point in time the DashboardModel object is in its final state and the connection should be available.

What is "unknown software exception (0xc00000fd)" error and how to avoid it?

I have created an AHK script named code_2, compiled it and placed it into my Startup folder so that it would automatically start running each time I turn on the computer.
The script checks a website for new updates and whenever an update on the website is detected, it downloads those updates using UrlDownloadToFile.
At first the script seemed to work fine, but recently I started receiving the following messages from my computer after my script has been running for about 15 minutes:
C:\Documents and Settings\Administrator\「開始」功能表\程式集\啟動\code_2.exe:
code_2.exe - 應用程式錯誤
應用程式發生例外 unknown software exception (0xc00000fd) 於位置 0x7c92eddc。
請按 [確定] 終止程式
請按 [取消] 進行程式偵錯
Any idea what this message is all about? (Sorry for the Chinese here, but I'd think that if you know this message by its number, you should be familiar with the contents.)
Anyway, here is the translated message:
C:\Documents and Settings\Administrator\Start Menu\Programs\Startup\code_2.exe: code_2.exe - Application Error
The exception unknown software exception (0xc00000fd) occurred in the application at location 0x7c92eddc.
Click on OK to terminate the program
Click on CANCEL to debug the program
I believe that 0xc00000fd is a stack overflow exception (http://support.microsoft.com/kb/315937). Without seeing your script, it is hard to say for sure what is going wrong, but this sort of thing is generally caused by recursing too deeply. I would check your script for any recursive functions and make sure that they are exiting before reaching too great a depth.
It's possible you're actually allocating too much on the stack. I'm not familiar with AHK, but it's possible the compiler is allocating a large amount of data (probably local variables) on the stack, too. If you define a large number of (or a number of large) local variables, this could happen.
It's also possible that the stack/memory is somehow getting corrupted, although this seems less likely to be the case when using a scripting language. It might be more likely when accessing native API from a scripting language, depending on how that is done.
The last possiblity I'm going to suggest here is that you're calling some API and causing it to allocate a lot of stack space as well, possibly by passing in bad parameters. Again, without knowing more specifics (especially what it's doing when it hits that exception), it's hard to say for sure.
I can think of some other reasons, but they're even less likely.

Resources