The word doing is the present participle of the verb do.
Here's how it works in the sentence:
* He is the subject of the sentence.
* had is the main verb, indicating possession.
* trouble is the object of the verb "had".
* doing is the present participle acting as a gerund, which functions as a noun. It's the object of the preposition "trouble."
* it is a pronoun referring to an unspecified object or action.
In essence, doing is acting like a noun, describing the type of trouble he had.