Help Bites
-
I thought we had a Visual Studio help thread but actually it's probably just a rant thread.
Is there a way in Visual Studio (not VS Code!) to see all the (C++) classes where a specific virtual function is reimplemented?
The "class view" can show me the classes derived from a given class, but it doesn't tell me which of those classes do, or do not, reimplement a specific virtual function, so I'm left browsing all of those classes to check by hand. Also the class view is apparently unable to list derived classes that are not in the same project as the base class and that makes it essentially useless in my case (most derivations being in different projects -- or maybe it's namespaces that cause it to fail? In any case, it fails).
I can also list all references to the symbol (either with the standard VS search, or with the Visual Assist one since I have that extension installed), but that mixes calls to and implementations of the function (or derived ones) with declarations. That's the best I have for now but it's not ideal.
Basically I just want some sort of list saying "
Base::foo()
is reimplemented inDerived1::foo()
,Derived2::foo()
etc." and nothing more (e.g. not "here is the list of wherefoo()
is used").
-
@hungrier said in Help Bites:
@Unperverted-Vixen I can see them in a text viewer, but it's unformatted and full of encoding artifacts like "=E2=80=99". Attachments are also right out, although for now I haven't needed them.
Anyway I found an open source mbox viewer tool that (after some fiddling) can get the job done.
-
@remi said in Help Bites:
ETA: re-reading the thread, I think the point above is even stronger, as there might not be a single term that is usable for all emergency services in one given country. Maybe in the US both police and fire services would understand being referred to as "agencies" but maybe in another country each service would use a totally different word. Typically if referring to physical locations i.e. "stations" in English -- which probably isn't the target here, but that's just to illustrate -- a French police station would be a "commissariat" or "gendarmerie" (depending on which administration they depend of... and getting it wrong would be a huge faux pas!), but a fire station would be a "caserne." Calling a fire station a "commissariat" would cause complete confusion, as would calling a police station a "caserne" (unless it's a "gendarmerie" in which case "caserne" might be understood but probably not exactly in the same way and that would also cause confusion, although of a slightly different type...).
Yes, "agence" would be strange for a fire or police station, but it's hard to find a neutral term that works in all cases. "Établissement" is the best I can think of.
-
@Zerosquare said in Help Bites:
works in all cases
Of course, that's the problem in all kinds of translations that are context-sensitive. Maybe the best that can be done is something like "organization ou agence ou établissement", or whatever terms are appropriate, and let the user understand which one is intended in his/her particular situation.
-
@Zerosquare said in Help Bites:
it's hard to find a neutral term that works in all cases. "Établissement" is the best I can think of.
The fun thing about context...
When you use the loan-word Etablissement in German, you’re either pretty stuck up or more likely using it as a euphemism for a brothel.
-
@Carnage said in Help Bites:
Importera användare från enhet tillhörande myndighet.
Minor typo, but since it's translations, it's maybe worthwhile pointing out.
-
@cvi said in Help Bites:
@Carnage said in Help Bites:
Importera användare från enhet tillhörande myndighet.
Minor typo, but since it's translations, it's maybe worthwhile pointing out.
Fån seems like an appropriate typo for government.
-
@Carnage said in Help Bites:
@cvi said in Help Bites:
@Carnage said in Help Bites:
Importera användare från enhet tillhörande myndighet.
Minor typo, but since it's translations, it's maybe worthwhile pointing out.
Fån seems like an appropriate typo for government.
TIL it means “idiot, stupid person”. So yes.
-
@dkf said in Help Bites:
TIL it means “idiot, stupid person”. So yes.
Related: iFån is a somewhat amusing nickname for the iPhone/iPhone users. The Swedish 'å' is pronounced somewhat close to the English 'o', so the two sound somewhat alike. The main difference is probably down to how you pronounce the 'i'.
-
-
Is it possible to create a local synonym for a function in T-SQL? Context -- the schema I'm in is really full, so I had to prefix my object names with the report type, and I'd rather not type that out IN the queries that make up that same report.
-
@Captain said in Help Bites:
Is it possible to create a local synonym for a function in T-SQL? Context -- the schema I'm in is really full, so I had to prefix my object names with the report type, and I'd rather not type that out IN the queries that make up that same report.
I've only used them for tables but it looks like you can for functions as well.
-
taskkill /pid 1234 /f
There is no running instance of the taskwmic process where "processid=1234" delete
Access is deniedpskill 1234
Access is deniedstop-process 1234
(no output)This thing is a NodeJS server started from a non-elevated powershell window, which is still responsive for the most part except it just refuses to close.
It was started with the same user I'm logged on with, which is an administrator. The above commands were run from an elevated powershell window.
The NodeJS process itself must be stuck doing something in kernel-mode, I guess.The parent powershell.exe process of node.exe doesn't seem to exist anymore, so I can't kill that either, and it's a mystery to me how I can still eg mark and copy text from it :/
Any ideas?
I'd rather not have to restart the server or kill this logon session. Just this one process.
-
I'm consuming some JSON in C#. Most of it is sensible and easily mapped to a class with Newtonsoft.Json, but a handful of the properties contain strings that look like this:
"\"\"[{\\\"\"country\\\"\":{\\\"\"en\\\"\":\\\"\"Canada\\\"\",\\\"\"fr\\\"\":\\\"\"Canada\\\"\"},[...]}]\"\""
. That is, multiply-escaped, multiply-quoted JSON strings. Why they did that instead of just leaving it as a normal JSON object/array in the property is a mystery to me, but in any case I need to work with it.Is there a quick, sane way to transform this mess into something that Newtonsoft can handle, without resorting to string.replace or some other such nonsense?
-
@Zecc said in Help Bites:
taskkill /pid 1234 /f
There is no running instance of the taskwmic process where "processid=1234" delete
Access is deniedpskill 1234
Access is deniedstop-process 1234
(no output)This thing is a NodeJS server started from a non-elevated powershell window, which is still responsive for the most part except it just refuses to close.
It was started with the same user I'm logged on with, which is an administrator. The above commands were run from an elevated powershell window.
The NodeJS process itself must be stuck doing something in kernel-mode, I guess.The parent powershell.exe process of node.exe doesn't seem to exist anymore, so I can't kill that either, and it's a mystery to me how I can still eg mark and copy text from it :/
Any ideas?
I'd rather not have to restart the server or kill this logon session. Just this one process.So what happened? 28 days later.
-
@Gribnit said in Help Bites:
So what happened? 28 days later.
I think there were some zombies? That nodejs process sure seemed like one
-
@hungrier said in Help Bites:
I'm consuming some JSON in C#. Most of it is sensible and easily mapped to a class with Newtonsoft.Json, but a handful of the properties contain strings that look like this:
"\"\"[{\\\"\"country\\\"\":{\\\"\"en\\\"\":\\\"\"Canada\\\"\",\\\"\"fr\\\"\":\\\"\"Canada\\\"\"},[...]}]\"\""
. That is, multiply-escaped, multiply-quoted JSON strings. Why they did that instead of just leaving it as a normal JSON object/array in the property is a mystery to me, but in any case I need to work with it.Is there a quick, sane way to transform this mess into something that Newtonsoft can handle, without resorting to string.replace or some other such nonsense?
Repeated normalization, vs a mutable buffer vs creating new strings. It can be done sanely, do you plan to? I think the JSON string type in w/ e is what might have the normalize you need.
-
@hungrier said in Help Bites:
I'm consuming some JSON in C#. Most of it is sensible and easily mapped to a class with Newtonsoft.Json, but a handful of the properties contain strings that look like this:
"\"\"[{\\\"\"country\\\"\":{\\\"\"en\\\"\":\\\"\"Canada\\\"\",\\\"\"fr\\\"\":\\\"\"Canada\\\"\"},[...]}]\"\""
. That is, multiply-escaped, multiply-quoted JSON strings. Why they did that instead of just leaving it as a normal JSON object/array in the property is a mystery to me, but in any case I need to work with it.Is there a quick, sane way to transform this mess into something that Newtonsoft can handle, without resorting to string.replace or some other such nonsense?
Maybe I misunderstand the problem, but since you already have a JSON parser just run it through that again (as many times as you have levels of escaping) instead of poorly parsing it with string replacements?
-
@topspin said in Help Bites:
Maybe I misunderstand the problem, but since you already have a JSON parser just run it through that again (as many times as you have levels of escaping) instead of poorly parsing it with string replacements?
The JSON parser doesn't like that it's quoted and escaped multiple times, and literally gives up before even starting:
An exception of type 'Newtonsoft.Json.JsonReaderException' occurred in Newtonsoft.Json.dll but was not handled in user code: 'Additional text encountered after finished reading JSON content: [. Path '', line 1, position 2.'
-
@hungrier having no C# available and not wanting to bother you with C++, I just typed the following up in the browser's console.
// One additional round of escaping to input your string (backslashes only, using single quotes) text = '"\\"\\"[{\\\\\\"\\"country\\\\\\"\\":{\\\\\\"\\"en\\\\\\"\\":\\\\\\"\\"Canada\\\\\\"\\",\\\\\\"\\"fr\\\\\\"\\":\\\\\\"\\"Canada\\\\\\"\\"},[42]}]\\"\\""' console.log(text); log> "\"\"[{\\\"\"country\\\"\":{\\\"\"en\\\"\":\\\"\"Canada\\\"\",\\\"\"fr\\\"\":\\\"\"Canada\\\"\"},[42]}]\"\"" // Use it as the value of a single '{"key": "value"}' JSON object o = JSON.parse('{"da_string": ' + text + '}'); console.log(o.da_string) log> ""[{\""country\"":{\""en\"":\""Canada\"",\""fr\"":\""Canada\""},[42]}]""
That is, I'm abusing the JSON parser's ability to parse strings, but to use it I have to put it into a fake JSON object. The result is one fewer layer of escaping.
Of course it'd be much easier if you can directly call the corresponding unescape function it's using for this under the hood, if it is accessible. (I.e. in JS I'd call whatever is the non-deprecated version of
unescape
instead of this nonsense)
-
@topspin said in Help Bites:
@hungrier having no C# available and not wanting to bother you with C++, I just typed the following up in the browser's console.
// One additional round of escaping to input your string (backslashes only, using single quotes) text = '"\\"\\"[{\\\\\\"\\"country\\\\\\"\\":{\\\\\\"\\"en\\\\\\"\\":\\\\\\"\\"Canada\\\\\\"\\",\\\\\\"\\"fr\\\\\\"\\":\\\\\\"\\"Canada\\\\\\"\\"},[42]}]\\"\\""' console.log(text); log> "\"\"[{\\\"\"country\\\"\":{\\\"\"en\\\"\":\\\"\"Canada\\\"\",\\\"\"fr\\\"\":\\\"\"Canada\\\"\"},[42]}]\"\"" // Use it as the value of a single '{"key": "value"}' JSON object o = JSON.parse('{"da_string": ' + text + '}'); console.log(o.da_string) log> ""[{\""country\"":{\""en\"":\""Canada\"",\""fr\"":\""Canada\""},[42]}]""
That is, I'm abusing the JSON parser's ability to parse strings, but to use it I have to put it into a fake JSON object. The result is one fewer layer of escaping.
Of course it'd be much easier if you can directly call the corresponding unescape function it's using for this under the hood, if it is accessible. (I.e. in JS I'd call whatever is the non-deprecated version of
unescape
instead of this nonsense)That. ^, using just the string type vs the object, to shave off one level of escape at a time. Normalizing it. Repeatedly.
And stops copies me Toki
-
-
@topspin said in Help Bites:
@Gribnit said in Help Bites:
And stops copies me Toki
I tried explaining the idea less inscrutably.
Scrutabilitalitly is for grandpa's guitars. "You is am dick! Am dick!" would have worked too. Not that I appreciate anything.
-
building a json string with the monster-mess as a property
I think that just puts me back to where I started, except without the rest of the properties of the original JSON. The more I think about it the more it seems like just string.replacing the whole thing may actually be a good solution
-
@hungrier said in Help Bites:
building a json string with the monster-mess as a property
I think that just puts me back to where I started, except without the rest of the properties of the original JSON. The more I think about it the more it seems like just string.replacing the whole thing may actually be a good solution
So note, you only do this to the one node, or, it really doesn't work. Recursion is maybe more natural than iteration for this one.
-
@Gribnit It didn't work with just the one node either, unless I would have to do some other tricky bit like adding an extra layer of escaping around it or something.
Anyway, what seems to be working now is
var usable = raw.Replace("\\\"\"", "\"").Replace("\"\"","");
I'll still need to do more testing to ensure that it works the same for the other properties that are encoded this way, and whether the result will always be an array of a single object, or could be an array with more than one, or if it could just be an object. But that's for later.
-
@hungrier said in Help Bites:
@Gribnit It didn't work with just the one node either, unless I would have to do some other tricky bit like adding an extra layer of escaping around it or something.
Anyway, what seems to be working now is
var usable = raw.Replace("\\\"\"", "\"").Replace("\"\"","");
I'll still need to do more testing to ensure that it works the same for the other properties that are encoded this way, and whether the result will always be an array of a single object, or could be an array with more than one, or if it could just be an object. But that's for later.
If the nesting is less predictable, you could make a regex that has the recursion embodied. It would be hideous. Example not provided. Too hideous.
Filed under: so many backslashes...
-
@hungrier not sure if this works (no way to try and I only glanced at the docs), but can you use
JsonReader.ReadAsString
on your input?
-
@Gribnit said in Help Bites:
@Zecc said in Help Bites:
taskkill /pid 1234 /f
There is no running instance of the taskwmic process where "processid=1234" delete
Access is deniedpskill 1234
Access is deniedstop-process 1234
(no output)This thing is a NodeJS server started from a non-elevated powershell window, which is still responsive for the most part except it just refuses to close.
It was started with the same user I'm logged on with, which is an administrator. The above commands were run from an elevated powershell window.
The NodeJS process itself must be stuck doing something in kernel-mode, I guess.The parent powershell.exe process of node.exe doesn't seem to exist anymore, so I can't kill that either, and it's a mystery to me how I can still eg mark and copy text from it :/
Any ideas?
I'd rather not have to restart the server or kill this logon session. Just this one process.So what happened? 28 days later.
We ended up restarting the server. Still no idea what happened, but fortunately it hasn't happened again.
-
@Zecc I feel that it would be a good idea to bet that it will recur tomorrow night. This is not to be taken as an estimate of odds, in itself.
-
@Gribnit said in Help Bites:
@Zecc I feel that it would be a good idea to bet that it will recur tomorrow night. This is not to be taken as an estimate of odds, in itself.
I hope so. I'm not working!
-
@hungrier said in Help Bites:
Is there a quick, sane way to transform this mess
Since the mess is insane in the first place…
-
I'm trying to figure out an issue with a T-SQL function I wrote a while back. It seems that the build job (Azure Devops) isn't installing the function, even though it is in version control.
A lead asked me to look through the build log, and I found an ultra-repetitive error regarding the function:
Warning SQL71502: Procedure: [CaseManagement].[sp307bFssOtherAdultCaseParticipants] contains an
unresolved reference to an object. Either the object does not exist or the reference is ambiguous because it
could refer to any of the following objects: [CaseManagement].[code_desc].[CaseManagement]::
[fnFirstMLastTitleCaseName], [CaseManagement].[fnFirstMLastTitleCaseName], ...OK, so what the heck? First off, it appears that the function is installed (the bold part). Second, it doesn't seem to actually be installed on the database server. Third, what are those random machine generated objects with the same name as my function?
I think I'm figuring out some of the issue... apparently I need to include my sql scripts in the solution file. Which makes sense, I guess.
-
(I feel sorry for the previous help bite that didn't get a single answer...)
Debugging a coredump with GDB, with many threads.
Does anyone know how to quickly find the thread whose stack contains a given function?
Typically, in the context I'm in right now, crashes only happen due to code in the thread that's executing
main()
, but for some reason (related to signal handlers, I think), GDB doesn't show that thread as the first one when loading the core. So I have to dig through all (other) threads to find the correct one.I can do that manually (
thread N
,where
(orbt
),thread N+1
,where
... until I hit the one that containsmain()
). Tedious.Right now the function I'm looking for is
main()
so thankfully I can speed this up withthread find <PID>
(the<PID>
being easy to find as corefiles are namedcore.<PID>
), since the thread that containsmain()
uses the PID for its name. I still have to copy-paste the correct PID every time, rather than just typing the same command from memory. And that wouldn't work if for some reason I was searching for another function thanmain()
.So, can I do some variation of
thread apply all bt <something>
that would quickly print the thread whose stack contains<something>
?I can't find any useful function to search the call stack. I can print it and navigate through it, but that seems about all...
-
@remi said in Help Bites:
(I feel sorry for the previous help bite that didn't get a single answer...)
Debugging a coredump with GDB, with many threads.
Does anyone know how to quickly find the thread whose stack contains a given function?
Typically, in the context I'm in right now, crashes only happen due to code in the thread that's executing
main()
, but for some reason (related to signal handlers, I think), GDB doesn't show that thread as the first one when loading the core. So I have to dig through all (other) threads to find the correct one.I can do that manually (
thread N
,where
(orbt
),thread N+1
,where
... until I hit the one that containsmain()
). Tedious.Right now the function I'm looking for is
main()
so thankfully I can speed this up withthread find <PID>
(the<PID>
being easy to find as corefiles are namedcore.<PID>
), since the thread that containsmain()
uses the PID for its name. I still have to copy-paste the correct PID every time, rather than just typing the same command from memory. And that wouldn't work if for some reason I was searching for another function thanmain()
.So, can I do some variation of
thread apply all bt <something>
that would quickly print the thread whose stack contains<something>
?I can't find any useful function to search the call stack. I can print it and navigate through it, but that seems about all...
Can you shell out to conventional text processing at all?
-
@remi Not quite what you're asking for, but if you run
gdb
in batch mode you can write the output to a file where you can search it. From our self-diagnostics tools:echo -e "info threads\n\nthread apply all bt full" >/tmp/gdb-x-$$ gdb -batch -x /tmp/gdb-x-$$ ${exec} ${core} > ${logfile}
-
@PleegWat yes, that's more or less what the accepted answer on SO where I found
thread find <PID>
says.The SO answer avoids loading the coredump twice (once in
gdb -batch
and then again when startinggdb
for real) by doing the logging from the session, which depending on how I'm doing things might be better or not.But the real issue I have with this approach is that I have to go through another file. I mean, it's not hard (), but it's... another file to go through. I can use a script with your command and a
grep
and run that, but it's still... another command to run outside ofgdb
(which means that if I forget about this thread thing and just startgdb
I have to go out of my way to run that command). I mean, none of that are huge issues, but it's not quite as streamlined as I would ideally hope.
-
@remi On the long term, you may also want to consider
pthread_setname_np
to give distinct names to threads performing different jobs. Though of course that doesn't help now and it won't help if the thread having problems is one in a pool of several dozens doing the same work.
-
@PleegWat The main problem here is that I don't really know where most of threads come from. We're using Qt and for some reason it always creates a lot of threads (related to event handling I think). And also, right now the application I'm debugging is actually a third-party one where I don't have the source code (I'm just writing some sort of plugin that's dynamically loaded into it), so I have even less access to how threads are created, which makes naming them even less feasible. Though I guess I could at least name those of the threads that I do control, that would probably be better than nothing...
But thanks anyway for the ideas.
If I get annoyed enough by this thread-searching thing I will probably make some script based on your suggestion, it's not ideal but would be better than what I currently have (I could even have the script start gdb for real after, which means I could get into the habit of running that instead of gdb -- the main downside being the double-read of the coredump, but it's not always 2.5 GB...).
-
@remi said in Help Bites:
it's not always 2.5 GB
I don't think I've experienced gdb slowness due to large coredumps and mine tend to be even larger. The more significant problem tends to be that the coredump can't leave the system it was generated on, either due to security or due to sheer size. If I'm lucky, I can install debug symbols and have shell access on the affected system. If I'm unlucky, I have to make do with what scripts like the above generate.
-
@PleegWat It's not so much that gdb is slow but rather that it takes some time to read the file. Anything after that read is fast, but not the initial start. Though now that I think of it, that's probably reading the executable (and its libraries) rather than the coredump.
We're talking a fairly minor annoyance here, but that's the case of my initial question anyway (
thread find <PID>
works for now and having to copy the PID really is a very minor gripe).The major annoyance is why the fuck does the application crash in the first place!!!
-
@remi I'm reminded of a string overflow in the stack several years ago. I ended up writing a diagnostics build which keeps track of function entry/return because the coredump gave no clue at all where the problem was occurring.
-
@PleegWat Took me a while to find out. Remember I said I'm using a third-party application with plugins that are dynamically loaded into it? Well it turned out that some object from one of those plugins was still referenced into another plugin after the first one had been unloaded.
Even
valgrind
wasn't of much help here, probably because the library containing that object had been unloaded, but the object itself had not been explicitly deleted (which would have triggeredvalgrind
). I guessvalgrind
can't track that as it would need to somehow track symbols, as opposed to hijackingnew
/delete
... I guess it could also hijackdlopen()
/dlclose()
but that maybe is too much work/impossible?Also, I found out that
gdb
doesn't really like to open a library that you are also recompiling in another terminal at the same time. 'twas a long time since I hadgdb
itself crash...
-
@PleegWat said in Help Bites:
@remi I'm reminded of a string overflow in the stack several years ago. I ended up writing a diagnostics build which keeps track of function entry/return because the coredump gave no clue at all where the problem was occurring.
I once have a string overflow wipe out part of the return address from a function. That was “interesting” to debug; it ultimately depended on UB relating to writing one-character strings into plain
char
variables, which worked on big-endian Solaris and… didn't on little-endian Linux.%c
and%1s
have many different behaviours!
-
@dkf Into or from? You need
%.1s
to safely read from a one-byte string pointer, otherwise you're relying on the next byte being zero.
Andsprintf
orsnprintf
always null-terminate, so a format string of%c
always writes two bytes, and%.1s
writes two bytes unless the passed char is zero.I'd expect the actual behaviour on both sides to rely not so much on endianness as on stack frame layout. Though of course both are platform-dependent.
-
@PleegWat said in Help Bites:
@dkf Into or from? You need
%.1s
to safely read from a one-byte string pointer, otherwise you're relying on the next byte being zero.This was
sscanf
, and the code was totally reliant onchar
being placed at the low-address end of its word. Which it was… on big-endian platforms.
-
-
@PleegWat It depends on what conversions you're using and what receiving buffers you have set up. And whether you check the return code. For example
sscanf
with%1s
is well defined provided you have a buffer of size at least 2 to write into.But using a single
char
variable as the target buffer for it is well into nasal demons territory.
-
python languge question.
How to do the following:
And your invocation of the program should be
python main.py XXX
Where XXX is something in my code an argument used in a function.
Above sounds to me like
collect sugar and flour on the mat in earth.
more understandable version of it is:
mix sugar and flour on the bowl [on the mat] [in earth].
.
-
@Gomesz785 It's hard to really figure out what an answerable version of your question is. So here it is from the other way round; you can try mapping from this explanation to your understanding of things yourself.
When you do
python main.py XXX YYY
you are telling the programpython
to run the scriptmain.py
(presumably in the current directory) with the list insys.argv
set to["XXX", "YYY"]
; it's up to the code at the top level ofmain.py
to decide what to do with that. Frequently that in involves argument parsing and calling functions/methods and stuff like that. Python has standard patterns for argument parsing (and some standard support modules) but the documentation for them usually ends up confusing me.There are other options for how to do it, but until you've got the basic one working you shouldn't take on the more complex stuff.