1. Some verbs (other than auxiliaries) can take other verbs immediately after themselves:
She sat knitting.
He helped (to) wash up.
I enjoy imagining what it will be like when I'm old enough to ride free on the buses.
These constructions are known as catenations; notice that the second verb may be in the -ing form, the bare infinitive, or the to-infinitive. Behaviour of individual verbs varies.
2. Some multi-word constructions resemble single-word verbs both semantically
(put on a hat = don a hat
the aeroplane put down on the island = the aeroplane landed on the island
take place can = occur, happen)
and in where they can be used in larger structures (as these examples also show).
'Have trouble' is a multi-word verb that catenates with the -ing form of a verb (though I can't think of an exact single-word replacement). These are closely related expressions, though:
Ron had trouble passing his exams.
Hermione enjoyed taking her exams.
Hermione took pleasure in taking her exams.
Ron struggled to pass his exams.
George regretted failing his exams.
Fred avoided taking his exams.
The -ing forms used here (in five of the examples) are at the verb end of the verb–noun gradience: they are present participles.
According to 5 of the first 6 references I checked in a Google search for "gerund meaning", including the AHDEL and Collins, the -ing form used in the original example is NOT a gerund, though FumbleFingers' example would qualify. The treatment of the verbal–nounal gradience of -ing forms found in Quirk et al shows that the term 'gerund' is probably best avoided. As my Google search indicates, it's not always used the same way anyway. If I was pressed, I'd say that (only) usage 2 below uses what most people would call a gerund:
Thieves stole a painting by Von Gaff yesterday. (deverbal noun)
Painting can be very therapeutic.
Leonardo was painting. (present participle)
Leonardo sat painting. (present participle)
Leonardo sat painting dinosaurs. (present participle)
Leonardo had trouble painting daleks. (present participle)